Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

overriding method in php

Mon Oct 27, 2008 12:01 am

Code:
<?php
  
class Rectangle {
    
public $height;
    
public $width;
   
    
public function __construct($width, $height) {
      
$this->width = $width;
      
$this->height = $height;
     }
    
     
public function getArea() {
      return
$this->height * $this->width;
     }
   }

  class
Square extends Rectangle {
    
public function __construct($size) {
      
$this->height = $size;
      
$this->width = $size;
    }
   
    
public function getArea() {
      return
pow($this->height, 2);
    }
   
  }

$obj = new Square(7);
$a = $obj->getArea();
echo
"$a";

?>




Post a reply
  Related Posts  to : overriding method in php
 Overriding Equals Method     -  
 Overriding the Function of a Base Class     -  
 overriding the direction of text within body content     -  
 What is an abstract method     -  
 What is a static method     -  
 Creating a Method in jsp     -  
 What is a native method     -  
 use out object in a method at jsp     -  
 toString method in class php     -  
 define a Class with a Method     -  

Topic Tags

PHP OOP