fork download
  1. <?php
  2. class Car extends CarDetails {
  3.  
  4. public $name;
  5. public $color = "Freaking Sexy White";
  6. public $price = "PHP 4,000,000.00";
  7.  
  8. public function __construct($name) {
  9.  
  10. $this->setName($name);
  11. $this->getColor();
  12. $this->getPrice();
  13.  
  14. }
  15.  
  16. public function setName($name) {
  17. $this->name = $name;
  18. }
  19.  
  20. public function setColor($color) {
  21. $this->color = $color;
  22. }
  23.  
  24. public function setPrice($price) {
  25. $this->price = $price;
  26. }
  27.  
  28. public function getName() {
  29. return $this->name;
  30. }
  31.  
  32. public function getColor() {
  33. return $this->color;
  34. }
  35.  
  36. public function getPrice() {
  37. return $this->price;
  38. }
  39.  
  40. public function showCarDetails() {
  41. print nl2br("I have an awesome car. Below are the details :)\r\n".
  42. "Brand: " . $this->getName() . "\r\n" .
  43. "Model: " . $this->getModel(). "\r\n" .
  44. "Color: " . $this->getColor() . "\r\n" .
  45. "Price: " . $this->getPrice()
  46. );
  47.  
  48.  
  49. }
  50.  
  51. }
  52.  
  53. class CarDetails {
  54.  
  55. public $model = "A7 Sportback";
  56. public $engine = "FSI technology";
  57.  
  58. public function __construct() {
  59.  
  60. }
  61.  
  62. public static function setModel($model) {
  63. $this->model = $model;
  64. }
  65.  
  66. public function getModel() {
  67. return $this->model;
  68. }
  69.  
  70. public function setEngine($engine) {
  71. $this->engine;
  72. }
  73.  
  74. public function getEngine() {
  75. return $this->getEngine;
  76. }
  77.  
  78. }
  79.  
  80.  
  81.  
  82. $car1 = new Car("Audi");
  83. echo $car1->showCarDetails();
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
I have an awesome car. Below are the details :)<br />
Brand: Audi<br />
Model: A7 Sportback<br />
Color: Freaking Sexy White<br />
Price: PHP 4,000,000.00