Method Override For Rectangle Class

 
    <?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";?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.