See Li Gang "crazy Java Handout", inside the interior of the class feel a bit scattered and not all, after reading or is not very clear how to use, so I wrote a program test a bit. You can see the rules of mutual invocation between an outer class and an inner class + static and non-static members, as shown in the following code.
The results of the operation are as follows:
Summarized as follows:
Note: When the error follows: "cannot refer to non-static from a static context", the problem is that a non-static method or a class that belongs to a non-static variable may not be actually serialized. Because you want to use a non-static method, you must instantiate the class to which it belongs.
For example, change the 40th line of code to INTER2. Staticinter ();
Compile:
The reason is that Staticinter (), although it is a static inner class, is itself a non-static method (instance method) and cannot be called by the inner class class name. Non-static method to invoke the method.
The correct approach is to instantiate the class to which the non-static method belongs, whether the owning class is a static class or a non-static inner class, that is, create an object of the owning class, and then call the non-static method.
The combination of the outer and inner classes + static and non-static variables of Java