-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathPoliformismo.java
More file actions
38 lines (33 loc) · 845 Bytes
/
Poliformismo.java
File metadata and controls
38 lines (33 loc) · 845 Bytes
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
class Animal {
void hablar() {
System.out.println("Este animal hace un sonido");
}
}
// Clase para definir un Perrito
class Perro extends Animal {
void hablar() {
System.out.println("El perro ladra!");
}
}
class Gato extends Animal {
void hablar() {
System.out.println("El gato maulla!");
}
}
class Leon extends Animal {
void hablar() {
System.out.println("El León ruge!");
}
}
public class Poliformismo {
public static void main(String args[]) {
// Crear instancias para mostrar mi Perro y mi Gato.
Animal miPerro = new Perro();
Animal miGato = new Gato();
Animal miLeon = new Leon();
// Mandaremos llamar al método hablar de cada uno de ellos.
miPerro.hablar();
miGato.hablar();
miLeon.hablar();
}
}