Class and Inhertance Example
Class and Inhertance Example
class Percentage
public $length;
public $width;
public $a;
function area($l,$w)
$this->length=$l;
$this->width=$w;
$this->a=$this->length*$this->width;
$p1=new Percentage();
$p1->area(2,3);
$p2=new Percentage();
$p2->area(5,6);
?>
Inheritance:
Class body
- derived_class_name is the name of new class which is also known as child class.
- base_class_name is the name of existing class which is also known as parent
class.
5. A derived class can access properties of base class and also can have its own
properties.
8. Example :
<?php
public $sname="s-xyz";
$s1->display ();
?>