|
1 , Concept:
Inner classes are divided into member inner classes, static inner classes, local inner classes, and anonymous inner classes, which are primarily used to manage the properties and methods of external classes.
2 , member inner class characteristics:
1) member inner classes are similar to member properties and methods in external classes
2) You can use the four-in-access modifier to decorate public private protected default
3) The Static keyword cannot be used in a member class
4) The properties and methods of an external class can be used within a member's inner class (including private)
5) If the inner class and the external class have the same properties and method names, then the inner class takes precedence over its own properties and methods, and in the inner class This also represents the inner class itself, and if you want to invoke the properties and methods in the outer class, you need to call through the new external class object
6) to create an inner class object, you need to create an external class object, creating an inner class object by creating an outer class object: Through the Outer class object. New inner class ();
7) Create inner class object in other class, need guide Package
3 , static inner class characteristics
1) Similar to the static properties and methods of the external class, defined with the static class name
2) Static or non-static properties and methods can exist
3) If the inner class attribute is the same as the external property name, call the internal if you want to call the external required new object
4) How to create the object: Inner in = new Inner (); When creating a guide package
5) Static internal classes are mainly used in builder mode
4 , local inner class
1) The declaration position of the local inner class is placed in the method
2) cannot use modifier
3) Non-static properties and methods can appear inside
4) Create object: Only in methods that declare inner classes
5) If you want the local inner class to execute, you must call the method that declares the local inner class
5 , anonymous inner class
1) Anonymous inner classes are primarily objects used for interface implementation classes
2) The advantage of an anonymous inner class is that it saves code, but it saves code if it is created once
3) The anonymous inner class is the object that created the subclass, and because it is anonymous, the parent class name is required instead
|