php code for inheritance

A  extends keyword can be used for inheritance.

Example :

class A
static $k=400;
function A()

function display()
echo "<br/>Inside parent class!!";
echo "<br/> parent class K: ".self::$k;

class B extends A
function show()
echo "<br/> from subclass k : ".parent::$k;

$objb = new B();


echo "<br/> I :".$objb->i;

echo "<br/> k :".$objb->show();
echo "<br/> Out side class K: ".A::$k;


Output :


Leave a Reply

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