-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstract.java
More file actions
58 lines (47 loc) · 1.04 KB
/
Abstract.java
File metadata and controls
58 lines (47 loc) · 1.04 KB
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
58
public class Abstract {
public static void main(String[] args) {
/*Horse h = new Horse();
h.eat();
h.walk();
System.out.println(h.color);
Chiken c = new Chiken();
c.eat();
c.walk();
*/
Mustang myHorse = new Mustang();
}
}
abstract class Animal {
String color;
Animal() {
System.out.println("animal constructor called");
}
void eat(){
System.out.println("Animal eats");
}
abstract void walk();
}
class Horse extends Animal {
Horse() {
System.out.println("Horse constructor called");
}
void changeColor() {
color = "white";
}
void walk(){
System.out.println("walks on 4 legs");
}
}
class Mustang extends Horse{
Mustang() {
System.out.println("Mustang constructor called");
}
}
class Chiken extends Animal{
void changeColor() {
color = "black";
}
void walk(){
System.out.println("walks on 2 legs");
}
}