Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // The parent class has hello method that returns "beep".
- class Car {
- //A private property or method can be used only by the parent.
- private $model;
- private $price;
- public function __construct() {
- echo "construct car";
- }
- public function hello()
- {
- return "beep";
- }
- public function setModel($model)
- {
- $this ->model = $model;
- }
- public function getModel()
- {
- return $this ->model;
- }
- public function setPrice($price)
- {
- $this->price = $price;
- }
- public function getPrice()
- {
- return $this ->price;
- }
- }
- //The child class has hello method that returns "Halllo"
- class SportsCar extends Car {
- public function __construct() {
- parent::__construct();
- }
- public function raceMode() {
- $this->price += 3000;
- }
- }
- //The child class has hello method that returns "Halllo"
- class FamilyCar extends Car {
- }
- //Create a new object
- $sportsCar1 = new SportsCar();
- //Get the result of the hello method
- $sportsCar1->setModel("Fiat 500");
- $sportsCar1->setPrice(5000);
- $sportsCar1->raceMode();
- echo $sportsCar1->getModel();
- $familyCar1 = new FamilyCar();
- //Get the result of the hello method
- $familyCar1->setModel("Fiat multipla");
- $familyCar1->setPrice(1000);
- echo $familyCar1->getModel();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement