Java-polymorphism, internal class, java-polymorphism,
1. Polymorphism:
1) meaning:
1.1) when a reference of the same type points to different objects, there are different implementations ------- behavior polymorphism: cut (), run (), teach ()...
1.2) the same object has different functions when it is modeled into different types ------- object polymorphism: Me, you, water...
2) upward shape:
2.1) references of the parent type point to the object of the subclass.
2.2) the following types can be modeled: parent class + Implemented interfaces
2.3) What can be clicked to see the reference type
3) Forced type conversion. There are only two successful conditions:
3.1) the referenced object is of this type.
3.2) the interface is implemented by referencing the object to which the object is pointed.
4) if the forced conversion does not meet the preceding two conditions, the ClassCastException type conversion exception occurs.
Suggestion: Use instanceof to determine whether the referenced object is of this type before strong conversion.
2. member Internal classes: ----- low actual application rate
1) Class middle-end class. The Outer class is called the Outer external class, and the inside class is called the Inner internal class.
2) Internal classes generally only serve external classes and are invisible to external users.
3) internal class objects can only be created in external classes.
4) The internal class can directly access members of the external class (including private). An implicit reference in the internal class points to the external class object that creates it.
External class name. this.
3. Anonymous internal class:
1) If you want to create an object of A Class (subclass), and you only need to create one object, this class does not need to be named, it is called an anonymous internal class.
2) access external variables in internal classes. The variables must be final
I am a beginner. If any updates are poor, I would like to thank you!
More highlights will be updated later!