An inner class (Inner Class) is a class that is defined in another class. Corresponding to this, the class containing the inner class is called the outer class.
The main functions of the inner class are as follows:
1. The inner class provides a better encapsulation that hides the inner class within the outer class and does not allow other classes in the same package to access the class
2. The method of the inner class can access all the data of the external class directly, including the private data
3. Functions implemented by internal classes can also be implemented using external classes, but sometimes it is easier to use internal classes
member Inner class (normal inner Class):
If an external class and an inner class have the same member variable or method, the inner class accesses its own member variable or method by default, and if you want to access the member variables of the external class, you can use the This keyword. Such as:
Static inner classes are internal classes of static adornments, which are characterized by:
1. Static inner classes cannot directly access non-static members of an external class, but can be accessed through the new external class (). Members
2. If the static member of the outer class is the same as the member name of the inner class, the static member of the external class can be accessed through the class name. static member; If the static member of the outer class is not the same as the member name of the inner class, the static member of the outer class can be called directly through the member name
3. When you create an object of a static inner class, you do not need an object of an external class, you can directly create an inner class object name = New inner Class ().
Method Inner class: The inner class of the method is the inner class definition in the method of the outer class, the inner class of the method is visible only within the method, that is, it can only be used inside the method.
Java Review Road 5