What is Inheritance

When the property and the methods of the parent class are accessed by the child class, we call the concept of inheritance. The Child class can inherit the parent method and give own method implement this property is called overriden method.

Example
class A{
public function printItem($string){
echo “Hi “.$string;
}
public function printPhp(){
echo “Hello Second”;
}
}
class B extends A{
public function printItem($string){
echo “Hello”.$string;
}
}

$b = new B();
$b->printItem(“World”);

OutPut

Hello World

What is Inheritance
Show Buttons
Hide Buttons