-
Notifications
You must be signed in to change notification settings - Fork 7.6k
/
人类感受继承与多态.java
53 lines (42 loc) · 1006 Bytes
/
人类感受继承与多态.java
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
class Man extends BasePerson implements Person {
private final String name, description;
protected Integer count;
Man(String name, String description) {
this.name = name;
this.description = description;
this.count = 0;
}
protected void move() {
System.out.println("I'm moving...");
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public int changeSomething() {
count -= 1;
return count;
}
}
class SuperMan extends Man {
SuperMan(String name, String description) {
super(name, description);
}
SuperMan() {
this("superMan", "I can fly.");
}
void fly() {
System.out.println("Fly! SuperMan!");
}
@Override
protected void move() {
System.out.println("I am flying...");
}
@Override
public int changeSomething() {
count += 1;
return count;
}
}