-
Notifications
You must be signed in to change notification settings - Fork 11
/
Demo.java
74 lines (61 loc) · 1.24 KB
/
Demo.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
package multi;
/**
*
*/
public class Demo {
static public class A {
public int a = 1;
public int getA() {
return a;
}
}
// B - наследник A
static public class B extends A {
public int a = 2;
public int b;
}
// Первый интерфейс
//-->
public interface I1 {
void m1();
}
//<--
// A
// / \
// B C
// \ /
// D
public interface I2 {
void m1();
default void m2(){
System.out.println("Default implementation");
}
}
static public class C extends A implements I1, I2 {
@Override
public void m1() {
System.out.println("C.m1");
}
@Override
public void m2() {
System.out.println("C.m2");
}
}
public static void main(String[] args) {
A a = new A();
B b = new B();
System.out.println("b.a = " + b.a);
System.out.println("b.getA() = " + b.getA());
b.a = 1;
b.b = 2;
C c = new C();
c.m1();
c.m2();
I1 i1 = c;
i1.m1();
I2 i2 = c;
i2.m1();
i2.m2();
//AbstractClass
}
}