Static inner class static Inner class
The simplest form of inner class.
The static keyword is added to the class definition.
Cannot have the same name as an external class.
is compiled into a completely separate. class file with the name Outerclass$innerclass.class in the form.
only static members and static methods of external classes can be accessed , including private static members and methods.
The static inner class object is generated in the following way:
Outerclass.innerclass inner = new Outerclass.innerclass ();
member Inner class member Inner class
The member inner class is also defined in another class, but is not defined with a static adornment.
A member inner class and a static inner class can be likened to non-static member variables and static member variables.
The member inner class is like an instance variable.
It can access all the member variables and methods of its outer class, whether static or non-static .
Create an instance of the member's inner class inside the outer class:
This.new Innerclass ();
Create an instance of an inner class outside the outer class:
(New Outerclass ()). New Innerclass ();
To access members of an external class in an inner class:
Outerclass.this.member
Local internal class local Inner class
Local inner classes are defined in a method and are smaller than the range of methods. Is the least used type in an inner class.
Like local variables, it cannot be modified by public, protected, private, and static.
Only local variables of the final type defined in the method can be accessed.
Local inner classes are defined in methods, so they can only be used in methods, that is, you can only generate instances of local inner classes within a method and invoke their methods.
Anonymous inner class anonymous Inner class
The anonymous inner class is a local inner class without a name, not using the keyword class, extends, implements, and no constructor method.
An anonymous inner class implicitly inherits a parent class or implements an interface .
Anonymous inner classes are used more often as a method parameter.
In the generated. class file, the anonymous class generates the Outerclass$1.class file, which is based on the first few anonymous classes.
Java Internal classes