-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathE9_14_ExtendsInterface.java
More file actions
116 lines (93 loc) · 1.61 KB
/
Copy pathE9_14_ExtendsInterface.java
File metadata and controls
116 lines (93 loc) · 1.61 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package unit9;
interface FirInterface {
void fFun();
void fFun2();
}
interface SecInterface {
void sFun();
void sFun2();
}
interface ThiInterface {
void tFun();
void tFun2();
}
interface ComInterface extends FirInterface, SecInterface, ThiInterface {
void cFun();
}
class Base {
public void bFun() {
}
}
class BaseP extends Base implements ComInterface {
@Override
public void fFun() {
// TODO Auto-generated method stub
System.out.println("BaseP f");
}
@Override
public void fFun2() {
// TODO Auto-generated method stub
System.out.println("BaseP f2");
}
@Override
public void sFun() {
// TODO Auto-generated method stub
System.out.println("BaseP s");
}
@Override
public void sFun2() {
// TODO Auto-generated method stub
System.out.println("BaseP s2");
}
@Override
public void tFun() {
// TODO Auto-generated method stub
System.out.println("BaseP t");
}
@Override
public void tFun2() {
// TODO Auto-generated method stub
System.out.println("BaseP t2");
}
@Override
public void cFun() {
// TODO Auto-generated method stub
System.out.println("BaseP c");
}
}
//参考前例,可以知道参数可以传入接口
public class E9_14_ExtendsInterface {
static void t1(FirInterface f) {
f.fFun();
f.fFun2();
}
static void t2(SecInterface s) {
s.sFun();
s.sFun2();
}
static void t3(ThiInterface t) {
t.tFun();
t.tFun2();
}
static void t4(ComInterface c) {
c.cFun();
}
public static void main(String[] args) {
BaseP bp = new BaseP();
t1(bp);
t2(bp);
t3(bp);
t4(bp);
}
}
/*
*
Output:
BaseP f
BaseP f2
BaseP s
BaseP s2
BaseP t
BaseP t2
BaseP c
*/