Mega Code Archive

 
Categories / Php / Class
 

Three levels of inheritance

<?php    class Employee {       private $name;       function setName($name) {          if ($name == "") echo "Name cannot be blank!";             else $this->name = $name;       }       function getName() {          return "My name is ".$this->name."<br />";       }    }        class Executive extends Employee {       function methodB() {          echo " my yacht!";       }    }        class CEO extends Executive {       function methodC() {             echo "tuck";       }    }    $ceo = new CEO();    $ceo->setName("Joe");    $ceo->methodB();    $ceo->methodC(); ?>