Monday, 3 April 2017

Inheritance

Inheritance is a mechanism of extending an existing class by inheriting a class we create a new class with all functionality of that existing class, and we can add new members to the new class.
When we inherit one class from another we say that inherited class is a subclass and the class who has inherit is called parent class.
-We declare a new class with additional keyword extends.
- PHP only supports multilevel inheritance.
Best example of multilevel inheritance in PHP

1.       class grandParent
2.       {
3.       //Body of grand parent class
4.       }
5.       class parent extends grandParent
6.       {
7.       //Body Of parent class
8.       }
9.       class child extends parent
10.    {
11.    //Body of child class
12.    }

Above example is so clear to understand, child class is extending parent class and parent class is extending grand parent.This was a very basic example to understand the concept of multilevel inheritance in php oops.

No comments:

Post a Comment