☜
☞
Inheritance
Inheritance in OOP = When a class derives from another class. The child class will inherit all the public and protected properties and methods from the parent class. In addition, it can have its own properties and methods. An inherited class is defined by using the extends keyword. Class Age extends Inheritance as its initial class. It the called the result name and myAge. When you write the name of inheritance same name of the method, it assumpts it to be a constructor.
<?php
class Inheritance{
public $name = "lokang";
public function name(){
return $this->name;
}
}
class Age extends Inheritance {
private $age = 40;
public function myAge(){
return $this->age;
}
}
$inheritance = new Inheritance();
echo $inheritance->name();
echo '<br>';
$age = new Age();
echo $age->myAge();
☜
☞