> parent reference or interface reference refers to its subclass object.
Animal a = new Cat();
The benefits of polymorphism are:The scalability of the program is improved.
Disadvantages of polymorphism: can be passed by a keyword. instanceof ;//Determines whether the object has implemented the specified interface or inherited the specified class.
instanceof type> ,Determine whether an object belongs to the specified type.
Student instanceof Person = true;//studentInherited the person class.
The characteristics of polymorphism in the members of the sub parent class are:
1,Member variables:In polymorphism, the parent parent variable is the same name.
In compile time: reference isCategory of referenced variablesIs there a member in the call? (No object is generated at compile time, only syntax errors are checked.)
Runtime: also a reference.Category of referenced variablesIs there a member in the call?
In a nutshell: Whether compiled or run, member variables refer to member variables in the class to which the reference variable belongs.
It’s easier to remember. = On the left.
2,Member functions.
Compile time: refer to the method of invocation in the class that the reference variable belongs to.
Run things: refer to the method of invocation in the class that the object belongs to.
Why is this so?Because in the sub parent class, for the same member function, there is one characteristic: overlay.
Simple sentence: member function, compile the class that the reference variable belongs to, and run to see the class that the object belongs to.
> = On the left, run to see = right.
3,Static functions.
Compile time: refer to whether there are invocation members in the class of the referenced variable.
Runtime: it also refers to the members who are invoked in the class that the reference variable belongs to.
Why is this so?Because static methods do not belong to the object, but belong to the class that the method belongs to.
Invoking the static method reference is the static method in which class the reference is invoked.
= On the left.