PHP Inheritence - php software - Phptpoint.com

PHP Inheritance

/ins>

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

Output
Addition=1500
subtraction=500
multiplication=500000


Eg ii

Output
shashi
new delhi
06275-258542
developer
Arise tech pvt ltd
9015501123

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

Output
Name = Amit Age = 26 Email = amittest@test.com Phone = 1234567890