Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

Php Programming Code Examples

Php > Php Classes Code Examples

An updated OOP - Inheritance

An updated OOP - Inheritance <?php /*PHP supports inheritance. Inheritance is the concept of one class being devined as a special case of a more general class. A Sport car is a car it inherits all its variables and functions from Car*/ class Car { var $description; //The aim here is to display the description and the cost of car! var $cost; function Car($d, $c) { $this->set($d, $c); } function display() { echo ("<br>$this->description, $this->cost"); } function set($d,$c) { $this->description = $d; $this->cost = $c; } function setDescription($d) { $this->description = $d; } function getDescription() { return $this->description; } } class sportcar extends Car { var $tyres; function sportcar($d, $c, $t) { $this->set($d, $c); $this->tyres = $t; } function displays() { //This is a function to display items named ie tyres echo "<br>$this->tyres"; // Here is to display the number of tyres $this->display(); } } $ordinary = new Car("Ford", 29050.00); // Constructor - new car $scar = new sportcar("Porshe",900000.00,4); // Constructor - new sportcar $ordinary->display(); $scar->displays(); //scar : Sportcar ?>