View Single Post
  #26 (permalink)  
Old 04-24-2008, 07:32 AM
jegan jegan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 161
jegan is on a distinguished road
Default Re: PHP Classes For Beginners

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;
}
}
?>
__________________
Thanks & Regards,
Jegan CBK
"We will either find a way, or make one!”
Reply With Quote