PHP Inheritence - php software -

PHP Inheritance

PHP 6 Months 100% Job Assistance Program. for more info... call on 8588829328

Inheritance in PHP

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.

Note : PHP only supports multilevel inheritance.

Eg i


Eg ii

new delhi
Arise tech pvt ltd

In the above example
A class person have defined with three properties $name,$address and $phone, with a method printPersonInf( )

Another class employee which is child class of person have also defined with three properties $occupation,$com_name,$buss_phone with a method printempInfo( ).

It means all the property of person class can accessible into employee class also so why
printPersoninfo( ) method is accessible here in printempInfo( ) method.

Now create the object of class employee and access all the property of its own and its inherited class.

Eg iii

Name = Amit Age = 26 Email = Phone = 1234567890

Latest Trending Technologies