Mega Code Archive

 
Categories / Php / Class
 

Inheritance example

<?php class Bird {   private $name;   private $breed;   private $price;      public function __construct($name, $breed, $price = 15) {     $this->setName ( $name );     $this->setBreed ( $breed );     $this->setPrice ( $price );   }   public function birdCall() {     printf ( "<p>%s says: *chirp*</p>\n", $this->getName () );   }   public function display() {     printf ( "<p>%s is a %s and costs \$%.2f.</p>", $this->getName (), $this->getBreed (), $this->getPrice () );      } } class Parrot extends Bird {   public function birdCall() {     printf ( "<p>%s says: *squawk*</p>\n", $this->getName () );   }   public function __construct($name) {     parent::__construct ( $name, 'parrot', 25 );   }   public function curse() {     printf ( "<p>%s</p>\n", $this->getName () );   } } ?>