Ejemplo n.º 1
0
    {
        echo 'It is an elephant<br>Name: ' . $this->name . '<br>Age: ' . $this->age . '<br>Sex: ' . $this->sex . '<br>Destination: ' . $this->destination . '<br><br>';
    }
}
class Giraffe extends Mamal
{
    public $necklength;
    public function __construct($name, $age, $sex, $necklength)
    {
        parent::__construct($name, $age, $sex);
        $this->necklength = $necklength;
    }
    public function info()
    {
        echo 'It is an giraffe<br>Name: ' . $this->name . '<br>Age: ' . $this->age . '<br>Sex: ' . $this->sex . '<br>Necklength: ' . $this->necklength . '<br><br>';
    }
}
$mike = new Animal('Mike', 29);
$mike->info();
$amphimike = new Amphibian('Amphimike', 29, 'true');
$amphimike->info();
$frogmike = new Frog('Frogmike', 29, 'false', 'green');
$frogmike->info();
$tritonmike = new Triton('Mike', 31, 'true', '20 mm');
$tritonmike->info();
$mamalmike = new Mamal('Mamalmike', '18', 'male');
$mamalmike->info();
$elephantmike = new Elephant('Mike', 12, 'female', 'India');
$elephantmike->info();
$giraffemike = new Giraffe('Nina', 4, 'female', '2m');
$giraffemike->info();
Ejemplo n.º 2
0
        return 'Je marche vers ' . $direction;
    }
}
class Voiture implements MoveInterface
{
    public function move($direction)
    {
        return 'Je roule vers ' . $direction;
    }
}
class Avion implements MoveInterface, AirInterface
{
    public function move($direction)
    {
        return 'Je vol vers ' . $direction;
    }
    public function decoller()
    {
        return 'Je décolle';
    }
    public function atterrir()
    {
        return 'J\'atteris';
    }
}
$elephant = new Elephant();
$voiture = new Voiture();
echo $elephant->move('l\'avant');
echo $voiture->move('le nord');
$avion = new Avion();
echo $avion->decoller();