- Polymorphism (polymorphism): The multiple manifestations of a certain class of things. (The reference of a parent type to a reference to a subclass type, or to an object of subclass type), greatly improves the extension of the program. The prerequisite for polymorphism must be that the class has a relationship with the class, either inherited or implemented. There is usually a premise that there is coverage. Polymorphism also has drawbacks, although extensibility is provided, but members in the parent class can only be accessed using a reference to the parent class.
- In polymorphism, you can refer to the object of the parent class (Animal a = new Cat ();) This is a type promotion, and next, you can also cast the parent class's reference to the type of the subclass (car c = (car) A;) However, it is wrong to convert the parent class object to a subclass type (Animal A = new Animal (); Cat C = (Car) a).
- instanceof Keyword: The object that determines whether an object is a class.
- The characteristics of member functions in polymorphism: At compile time, see if there is a method called in the class to which the referenced variable belongs. If there is, the compilation passes, and if not, the compilation fails. At run time, see if there are methods called in the class to which the object belongs. The simple summary is: the member function in polymorphic call, compile look to the left, run look to the right.
- The characteristics of member variables in polymorphism are referred to the left (the class to which the reference variable belongs)
- In polymorphism, the characteristics of static member functions, both compiled and run, are referred to the left.
- Object class: Is the direct or indirect parent class for all objects.
Beginners To learn Java, is javase, every day I learn from the day and notes, I hope you can criticize and advice, and promote common progress! Eighth Day!