Ans
I have written a program that inherits our Box class. Here the base class is Box and the derived class is BoxChild.
We have a scenario to find the weight of a box. So we need to write a new class with width, height and weigh member variables. But this will lead to us to do lot of workload. But we can inherit our Box object and we can add required thinks in child class.
PHP Code:
//Base class
<?php
class Box
{
var width;
var height;
function box($pmWidth,$pmHeight)
{
$this->width =$pmWidth;
$this->height=,$pmHeight;
}
function area()
{
return $this->width*$this->height;
}
}
//Child class
Class BoxChild extends Box
{
var $weight
function BoxChild($pmHeight,$pmWidth,$pmWeight)
{
$this->weigth=$pmWeight;
parent::height=$pmHeight;
parent::width=$pmWidth;
}
function getWeight()
{
return $this->weight;
}
}
?>