-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolimorfismo.php
57 lines (45 loc) · 1.18 KB
/
polimorfismo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
// Polimorfismo.
abstract class Animal {
public function comunicar() {
return "Som";
}
public function mover() {
return "Anda";
}
}
class Cachorro extends Animal {
public function comunicar() {
return "Late";
}
public function mover() {
return "Corre";
}
}
class Gato extends Animal {
public function comunicar() {
return "Mia";
}
public function mover() {
return "Dorme";
}
}
class Passaro extends Animal {
public function comunicar() {
return "Canta";
}
public function mover() {
return "Voa e " . parent::mover();
}
}
$mutley = new Cachorro();
echo $mutley->comunicar() . "<br>";
echo $mutley->mover() . "<br>";
echo "-----------------------<br>";
$garfield = new Gato();
echo $garfield->comunicar() . "<br>";
echo $garfield->mover() . "<br>";
echo "-----------------------<br>";
$lourojose = new Passaro();
echo $lourojose->comunicar() . "<br>";
echo $lourojose->mover() . "<br>";