Chapter III polymorphism One, writing parent-child class
1. Polymorphism is characterized by the ability to express multiple types of ecology, the same implementation interface, the use of different instances to perform different operations
2. A reference type that performs different operations with different instances. (The parent class refers to the child class object)
Benefits of using polymorphism: by polymorphism you can reduce the amount of code in a class, which can improve the scalability and maintainability of your code.
3. Implementing ideas to write subclasses, subclasses overriding parent class methods
When run, uses the parent class's type, the subclass of the object.
Ii. two elements to achieve polymorphism
1. Rewrite
Using the parent class type
Rules for method overrides
In the subclass of the inheritance relationship
The overridden method name, parameter, and return value type must be the same as the parent class
Private methods are not tender tricks and thus cannot be rewritten.
2.Instanceof operator
Instanceof class or interface
This operation is used to determine whether an object belongs to a class or implements an interface. The result is true or false.
Rules when a subclass is converted to a parent class:
Transformation of subclass to parent class (up conversion)
Conversion of parent class to subclass (down conversion)
Using Java to implement object-oriented chapter III