-
Notifications
You must be signed in to change notification settings - Fork 1
/
ClassStaticNestedTest.java
59 lines (32 loc) · 1.35 KB
/
ClassStaticNestedTest.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
class OuterClass {
private static int outerField;
static class StaticNestedClass {
private int nestedField;
void method() {
outerField = 1; // access only to outer static members
}
}
class InnerClass {}
private static class PrivateStaticNestedClass {}
static interface StaticNestedInterface {}
interface ThisIsStaticNestedInterfaceToo {}
void method() {
new StaticNestedClass().nestedField = 2; // full access
}
}
interface OuterInterface {
static class StaticNestedClass {}
class AgainStaticNestedClass {} // any field in interface is: public static
}
class ClassStaticNestedTest {
public static void main(String[] args) {
OuterClass.StaticNestedClass snc = new OuterClass.StaticNestedClass();
OuterClass.InnerClass ic = new OuterClass().new InnerClass(); // NOT LIKE THIS: new OuterClass.InnerClass();
// NO! Private modifier!
//OuterClass.PrivateStaticNestedClass psnc = new OuterClass.PrivateStaticNestedClass();
OuterClass.StaticNestedInterface sni = new OuterClass.StaticNestedInterface() {};
OuterClass.ThisIsStaticNestedInterfaceToo tisnit = new OuterClass.ThisIsStaticNestedInterfaceToo() {};
OuterInterface.StaticNestedClass oisnc = new OuterInterface.StaticNestedClass();
OuterInterface.AgainStaticNestedClass asnc = new OuterInterface.AgainStaticNestedClass();
}
}