Exemple #1
0
 public function move($distance)
 {
     // $this->money = 0 + 10*0.65  = 6.5
     $result = parent::move($distance);
     if ($result == true) {
         $this->money = $this->money + $distance * $this->price_per_km;
     } else {
         echo "Nema nafta";
     }
 }
{
    public function __construct($x = 0, $y = 0)
    {
        parent::__construct($x, $y);
    }
    //это делать не обязательно берет из родительского конструктора
    public function move($x, $y)
    {
        $this->strMove($x, $y, "легковой");
    }
}
class Truck extends Auto
{
    private $capasity;
    public function __construct($x = 0, $y = 0, $capasity = 5000)
    {
        parent::__construct($x, $y);
        $this->capasity = $capasity;
    }
    //это делать не обязательно берет из родительского конструктора
    public function move($x, $y)
    {
        $this->strMove($x, $y, "грузовой");
    }
}
$auto = new Auto();
$car = new Car();
$truck = new Truck();
$auto->move(10, 10);
$car->move(10, 10);
$truck->move(10, 10);
Exemple #3
0
<?php

require_once "car.php";
require_once "truck.php";
require_once "taxi.php";
$car = new Car(1, 'Black', 5);
$result = $car->move(100);
if ($result == true) {
    echo "We are magicians";
} else {
    echo "Sipi nafta";
}
exit;
// fuel, color, number , perKm, startingMoney, seats
$taxi = new Taxi(30, 'Black & Yellow', '6665', '0.65', 0, 4);
echo "<pre>";
print_r($taxi);
$taxi->move(10);
echo "<pre>";
print_r($taxi);
$taxi->move(6);
echo "<pre>";
print_r($taxi);
$taxi->move(200);
echo "<pre>";
print_r($taxi);
$taxi->move(100);
echo "<pre>";
print_r($taxi);