PHP Inheritance- Tutorialpath

PHP Inheritance
PHP 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 (child) and the class who has inherit is called parent class (Base Class).

Use additional keyword ‘extends’ for a inherit of class.

Advantage of using inheritance in php oops, we can share properties of one class to other class.

Note: PHP only support’s Multi-level inheritance, but with the help of interface we can achieved multiple inheritance.

Multilevel or Multiple inheritance in PHP ?

Here is a sample code example which tell you the concept of inheritance in php oops which means how you will use inheritance in php, where you will use extend keyword.

syntax inheritance
syntax inheritance

Example:

inheritance example
inheritance example

Output:

inheritance example output
inheritance example output

Leave a Reply

Your email address will not be published. Required fields are marked *