2018-05-07
Inner class
You can define another class within one class.
Why use internal classes?
1) Enhanced encapsulation, hides the inner class inside the outer class, and does not allow other classes to access the inner class.
2) The inner class can improve the readability and maintainability of the code, embed the small class into the inner class, and the structure can be closer.
3) Internal classes can access external class members directly
The inner class is divided into four types according to the different modifiers or location of the position:
1) Instance inner class: the inner class does not use static adornments.
2) static inner class: The inner class uses the static modifier.
3) local inner class: The inner class defined in the method.
4) anonymous inner class: Suitable for use only once inner class, belongs to the special case of local inner class.
An inner class can be thought of as a member of an external class, like a field. The inner class can use public, default, protected, private adornments, and final adornments.
First, the instance inner class
An inner class that does not use the static modifier, which describes an inner class that belongs to an object of an external class, does not belong to the external class itself.
Characteristics:
1. Before creating an instance inner class, an external class object must exist to create an inner class object. (There must be an external class object when there is an inner class object)
Second, static internal class
Third, local inner class
Iv. Anonymous Internal classes
Second, Java object-oriented (17) _ Inner class