When one class shares code from another class, then this process is known as inheritance.
In other words, when a class is derived from another class then this process is known as inheritance. The derived class is known as child class or subclass or derived class and the other class from which the child derived is the parent class or superclass.
extendskeyword when it inherits the parent class.
Let us understand the above example.
We inherited the Mango class from the Fruit class
The child class
displayMessage() method access the property
$color of parent class.
Please keep in mind that the protected access modifier is visible in the defined class as well as inside the inheritance class.
By declaring a property and method to protect, you can not access outside of the child and parent class. Let us understand it with the help of an example.
Inherited methods can be overridden inside the child class by redefining the same method.
Let us see it with the help of an example.
The final keyword is used for :