-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMultipleInheritance.java
81 lines (66 loc) · 2.48 KB
/
MultipleInheritance.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
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
interface Interface1 {
default void method() {
System.out.println("Instance");
}
}
interface Interface2 {
static void method() {
System.out.println("Static");
}
}
class MultipleInheritance implements Interface1, Interface2 {
public static void main(String args[]) {
//MultipleInheritance.method(); // WON'T work: error: non-static method method() cannot be referenced from a static context
Interface2.method(); // prints "Static"
new MultipleInheritance().method(); // prints "Instance"
_34.test();
_6.test();
}
}
//-----------------------------------------------------------------------------
interface Interface3 {
static void method() {
System.out.println("Static 3");
}
}
interface Interface4 {
static void method() {
System.out.println("Static 4");
}
}
class _34 implements Interface3, Interface4 {
static void test() {
//method(); // WON'T work: error: cannot find symbol
Interface3.method(); // prints "Static 3"
Interface4.method(); // prints "Static 4"
}
}
//-----------------------------------------------------------------------------
interface Interface5 {
static void method() {}
//default void method() {} // WON'T work: error: method method() is already defined in interface Interface5
}
//-----------------------------------------------------------------------------
interface Interface6 {
int VALUE = 0;
int OTHER = 1;
}
class _6_1 {
static int VALUE = 2;
static int UNKNOWN = 3;
}
class _6 extends _6_1 implements Interface6 {
static int OTHER = 4;
static void test() {
//System.out.println("VALUE=" + VALUE); // error: reference to VALUE is ambiguous
//System.out.println("_6.VALUE=" + _6.VALUE); // error: reference to VALUE is ambiguous
System.out.println("_6_1.VALUE=" + _6_1.VALUE); // prints 2
System.out.println("Interface6.VALUE=" + Interface6.VALUE); // prints 0
System.out.println("OTHER=" + OTHER); // prints 4
System.out.println("Interface6.OTHER=" + Interface6.OTHER); // prints 1
System.out.println("_6.OTHER=" + _6.OTHER); // prints 4
System.out.println("UNKNOWN=" + UNKNOWN); // prints 3
System.out.println("_6_1.UNKNOWN=" + _6_1.UNKNOWN); // prints 3
System.out.println("_6.UNKNOWN=" + _6.UNKNOWN); // prints 3
}
}