Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Transport{
- protected $model;
- protected $speed;
- function __construct($model, $speed){
- $this->model = $model;
- $this->speed = $speed;
- }
- protected function setSpeed($newSpeed){
- $this->speed = $newSpeed;
- }
- protected function getSpeed(){
- return $this->speed;
- }
- protected function getModel(){
- return $this->speed;
- }
- }
- class Car extends Transport{
- private $fuelType;
- function __construct($model, $speed, $fuelType){
- parent::__construct($model, $speed);
- $this->fuelType = $fuelType;
- }
- public function getFuelType(){
- return $this->fuelType;
- }
- public function printInfo(){
- echo __CLASS__ . ":<br>"
- . "Model: " . $this->model . "<br>"
- . "Speed: " . $this->speed . "<br>"
- . "FuelType: " . $this->fuelType . "<br>"
- . "<hr>";
- }
- }
- class Plane extends Transport{
- private $wingSpan;
- public function __construct($model, $speed, $wingSpan){
- parent::__construct($model, $speed);
- $this->wingSpan = $wingSpan;
- }
- public function setWingSpan($newWingSpan){
- $this->wingSpan = $newWingSpan;
- }
- public function getWingSpan(){
- return $this->wingSpan;
- }
- public function printInfo(){
- echo __CLASS__ . ":<br>"
- . "Model: " . $this->model . "<br>"
- . "Speed: " . $this->speed . "<br>"
- . "WingSpan: " . $this->wingSpan . "<br>"
- . "<hr>";
- }
- }
- echo "<br><h2>Cars</h2><br>";
- $car1 = new Car("Lada", 30, "disel");
- $car2 = new Car("Opel", 10, "benzin");
- $car3 = new Car("Bulgareno", 50, "rakia");
- $car1->printInfo();
- $car2->printInfo();
- $car3->printInfo();
- echo "<br><h2>Planes</h2><br>";
- $plane1 = new Plane("Boing", 200, 50);
- $plane2 = new Plane("Airbus", 50, 70);
- $plane3 = new Plane("Mig", 1000, 20);
- $plane1->printInfo();
- $plane2->printInfo();
- $plane3->printInfo();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement