php code for inheritance

A  extends keyword can be used for inheritance.

Example :

<?
class A
{
static $k=400;
function A()
{

$this->i=100;
self::$k=500;
}
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();

$objb->display();

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


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

?>

Output :

Comments

Leave a Reply

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

49506