Local inner class features:
1. A class defined in a code block or method body is called a local inner class
2. The local inner class accesses the properties and methods of the external class using the "external class name." This. The name of the property and the external class name. This is the form of the method name (parameter)
3. Completely hidden from the outside world, the object can only be generated within the scope.
Local inner classes have the following limitations:
1. Local classes cannot add access modifiers because they are not class members
2. The member inner class cannot duplicate the name of the external class
3. Local internal class accesses local variables within the scope, the local variable needs to be final decorated
public class Localinnerclass {public static void main (string[] args) {//TODO auto-generated method StubOuter3 Outer3 = NE W Outer3 (); Outer3. Outershow ();}} class Outer3{private int num1 = 1;private static int num2 = 2;public void Outershow () {final int num4 = 4;//FIANL seems to have been repaired, not declared For final in the inner class can also be used (can be removed final)//inner Inner = new Inner (), cannot be instantiated here, because the Inner class has not been initialized, you cannot call that class inner{// Local inner class cannot add access modifier public void show () {int num1 = 10; System.out.println (NUM1); System.out.println (OUTER3.THIS.NUM1);//Call the properties of the external class System.out.println (outer3.num2);// Call external static property notation System.out.println (NUM4);}} Inner Inner = new Inner ();//should be instantiated here Inner.show ();}}
Local inner class of the member inner class of the Java inner class