static inner classes are internal classes of static adornments
Characteristics of Static internal classes :
1. Static inner classes cannot directly access non-static members of an external class, but can be accessed through the new external Class (). member ;
2. If a static member in an external class is the same as a member name in a static inner class, you can access the static members of the external class by using the class name.
If the static members in the outer class and the member names in the static inner class are different, the static members of the external class can be accessed directly from the static member name ;
3. Create an object of the static inner class without requiring an object of the outer class, directly with the static Inner class object name = new static inner class ();
1 Packagecom.imooc.test003;2 3 Public classOuter {4 5 Private intA = 10;//ordinary member variables for external classes6 Private Static intb = 20;//static member variables for external classes7 Private Static intc = 30;//static member variables for external classes8 9 //Inner class innerTen Public Static classinner{ One A Private intB = 40; - - Public voidTest () { theSYSTEM.OUT.PRINTLN ("Accessing ordinary member variables in an external Class A:" +NewOuter (). a); -SYSTEM.OUT.PRINTLN ("Access static member variable B with the same name as the member variable in the inner class in the external class:" +outer.b); -SYSTEM.OUT.PRINTLN ("Accessing ordinary member variable B in an inner class:" +b); -System.out.println ("A static member variable that accesses a member variable in an external class with a different name in the inner Class C:" +c); + } - + } A at Public Static voidMain (string[] args) { -Inner in =NewInner ();//to create an object of an inner class - in.test (); - } - -}View Code
Reference: MU-Class network (http://www.imooc.com/)
Static inner classes in Java