Public class outer {
Public string name = "outer";
Public static void main (String Argv []) {
// inner myinner = new inner (); // Directly create this sentence to create a compilation error
Outer myouter = new outer (); // Create an external class object
Outer.inner myinner = myouter.new inner ();
Myinner.showname ();
} // end of main
// The following code is used to test this N annoyance
Public void amethod () {
Outer myouter = new outer ();
Outer.inner myinner = myouter.new inner ();
Myinner.showname ();
}
// Non-static method access non-static internal class
PRIVATE CLASS INNER {
String name = new string ("inner");
Void showname () {
System.out.println (Name);
}
} // End of Inner Class
}
In the non-static method, the non-static internal class is created directly to the internal class: new inner (). Showname (); of course, this N annoying method is also possible to modify the Private Class Inner to change to Static Private Class Inner, then static The access static internal classes are also objects that directly create the internal class, inner myinner = new inner (), or Outer.inner Myinner = new Outer.inner () can also be passed, and this N-annoying method is above. It can be used in three cases.