-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMultiInterfaces.java
More file actions
45 lines (33 loc) · 843 Bytes
/
MultiInterfaces.java
File metadata and controls
45 lines (33 loc) · 843 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
package innerclasses;
/**
* RUN:
* javac innerclasses/MultiInterfaces.java && java innerclasses.MultiInterfaces
* OUTPUT:
* takesA(X())
* takesA(Y())
* takesB(X())
* takesB(innerclasses.Y$1@1d5550d)
*/
public class MultiInterfaces {
static void takesA(A a) { System.out.println("takesA("+a+")"); }
static void takesB(B b) { System.out.println("takesB("+b+")"); }
public static void main(String[] args) {
X x = new X();
Y y = new Y();
takesA(x);
takesA(y);
takesB(x);
takesB(y.makeB());
}
}
interface A {}
interface B {}
class X implements A, B {
public String toString() { return "X()";}
}
class Y implements A {
B makeB() {
return new B() {};
}
public String toString() { return "Y()";}
}