Polymorphism: The same behavior, different implementations.
Polymorphism is divided into: static polymorphism and dynamic polymorphism.
Static polymorphism: The implementation and effect of the method is determined at compile time. --using overloads to implement
Dynamic polymorphism: The implementation and performance of the method can be determined after running. --using dynamic binding and overriding implementations
Dynamic binding Technology: Reference data type conversions, instanceof keywords
Reference data type conversion: Transformation up: The reference to the parent class is directed to the object of the child class.
Downward transformation: After running, it is true that this class of references point to this class of objects or to the subclass object in order to succeed.
instanceof Keyword: Used to determine the true type of a run-time object and to determine whether an object is an instance of a class. Returns TRUE/FALSE.
Usage: Object instanceof class name
Polymorphic applications: polymorphic parameters: That is, when a method's formal parameter is a reference, any object that is compatible with the reference can be passed to the method.
Polymorphic Collection: is a collection of different data types. Example: object[]
Abstraction (abstract):
When the abstract modification method, the method is an abstract method, the expression class has this method, the implementation of the method is completed by subclasses.
When abstract modifies a class, the class is an abstract class, and an abstract class cannot produce an object.
Note: 1. Classes with abstract methods must be abstract classes
2. Abstract classes may not have abstract methods (syntax allowed)
3, abstract class in addition to using abstract modification, and other similar to ordinary classes, attributes, constructs (for subclasses), the method has been implemented and so on.
4. Subclasses must override all the abstract methods of the parent class when inheriting the abstract class, otherwise this class is also an abstract class.
Comparison of abstract and final modified classes:
Abstract design Parent class, cannot produce object, can inherit.
Final design End class, cannot be inherited, can produce objects.
DAY14 Polymorphism and abstraction