Inheritance :- When a class derives from another class. The child class will inherit all the public and protected properties and methods from the parent. An inherited class is defined by using the extends
keyword.
There are three type of Inheritance:
- Single inheritance –
Single inheritance supports php. In a single class can be derived by one class unique. We require to have two classes in between this method. One is the parent class and the other a child class itself.
2. Multilevel inheritance
In this type of inheritance, there will be more than 2 classes involved. In Multilevel inheritance Parent class will be inherited by a child and then further child class will be inherited by another child class.
3. Hierarchical inheritance
When more than one class inherit to a single class. This type of inheritance known as Hierarchical Inheritance
SINGLE INHERITANCE
Ex:-
https://gist.github.com/AvinashKumar33/745e6e3769016a43ac7072b64dd388c0
Output:-
Multilevel inheritance
Ex:-
https://gist.github.com/AvinashKumar33/fdabd7b9d34f2d367c48d3fbb2ea72c8
Output:-
Hierarchical inheritance
Ex:-
https://gist.github.com/AvinashKumar33/fd56b51f174a149e18067a62f9318b52
Output:-