-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDogsAndRobots.java
More file actions
61 lines (46 loc) · 988 Bytes
/
DogsAndRobots.java
File metadata and controls
61 lines (46 loc) · 988 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package btp.oneP;
public class DogsAndRobots {
public static void main(String[] args) {
PerformingDog d = new PerformingDog();
Robott r = new Robott();
Communicate.perform(d);
Communicate.perform(r);
}
}
interface Performs{
void speak();
void sit();
}
class PerformingDog extends Dog implements Performs{
@Override
public void speak() {
System.out.println("Woof!");
}
@Override
public void sit() {
System.out.println("Sitting!");
}
public void reproduce(){}
}
class Robott implements Performs{
@Override
public void speak() {
System.out.println("Click!");
}
@Override
public void sit() {
System.out.println("Clank!");
}
public void oilChange(){}
}
class Communicate{
public static <T extends Performs> void perform(T performs){
performs.speak();
performs.sit();
}
//下面和上面的一样,不构成重载
/*public static void perform(Performs p){
p.speak();
p.sit();
}*/
}