I. location
Defined under a class and modified by static
Two, structure
Static and non-static attributes and methods can be defined under static internal classes
3. Static Internal Classes Access External Classes
1. Non-static attributes and methods of external classes cannot be accessed
2. Calling attributes [methods]:
2.1 Write the attribute name directly [call method name]--- Essentially, it's the second.
2.1 External Class. Attribute Name [Method Name]
Source code:
class Outter { private static int b =3; public static void test(){ System.out.println("External Class Static Method"); } static class Inner{ public void get(){ System.out.println(b);//External static properties can be accessed test();//Access to external class static methods } } }
Decompiled source code:
class Outter { private static int b; public static void test() { System.out.println("\u5916\u90e8\u7c7b\u9759\u6001\u65b9\u6cd5"); } static { Outter.b = 3; } static class Inner { public void get() { System.out.println(Outter.b); Outter.test(); } } }
IV. External Classes Access Static Internal Classes
class Outter { private static int b =3; public static void test(){ System.out.println("External Class Static Method"); } static class Inner{ private int a = 1; private static int b = 2; public void get(){ System.out.println("get"); } public static void get2(){ System.out.println("get2"); } } public static void main(String[] args) { //Static variables-Method --One way System.out.println(Inner.b); Inner.get2(); //Static variables-Method --Mode two System.out.println(Outter.Inner.b); Outter.Inner.get2(); //Non static state--Mode 1 System.out.println(new Inner().a); new Inner().get(); //Non static state--Mode 2 System.out.println(new Outter.Inner().a); } }
Above is a summary of static internal classes, there are some wrong places, please give us more advice, and make progress together!!!