animal1 = $animal1; $this->animal2 = $animal2; $this->animal3 = $animal3; } public function BuildSentence() { $fin_sentence = 'The animals are a ' . $this->animal1 . ', a ' . $this->animal2 . ' and a ' . $this->animal3; return $fin_sentence; } public function getAnimal1() { return $this->animal1; } public function getAnimal2() { return $this->animal2; } public function getAnimal3() { return $this->animal3; } public function setAnimal1($value) { $this->animal1 = $value; } public function setAnimal2($value) { $this->animal2 = $value; } public function setAnimal3($value) { $this->animal3 = $value; } } //Create SubClass class Ext_Animals extends Animals{ public $new_sentence; public function __construct($new_sentence, $animal1, $animal2, $animal3) { $this->new_sentence = $new_sentence; // Call Animals Constructor parent::__construct($animal1, $animal2, $animal3); } //get and set of properties public function getNewSentence() {return $this->new_sentence;} public function setNewSentence($value) {$this->new_sentence = $value;} } echo '
Inheritance means that you can create a new class from a current class. This new class can then use the properties and methods of the original class it inherited from.
'; echo 'The new class that has been derived is called a subclass, derived class or a child class. A good example is a Car Class. All cars, regardless of make, inherits the properties and methods of the Car superclass.
'; $sentence = new Ext_Animals('They all can be domesticated', 'dog', 'cat', 'bird'); print $sentence->BuildSentence(); //Inherited from Superclass : Animals ?> new_sentence; ?>