Polymorphism of the three major features in java, and java feature Polymorphism
I. Polymorphism: an object has multiple manifestations (the reference type variable of the parent class points to the object of the subclass)
2. multi-state conditions: 1. There must be an inheritance relationship 2. There must be method rewriting.
Iii. int [] a; // a reference type variable --> // reference the variable of the in type array
4. Variables of reference type: array, String, Object
Animal class, Dog, Fish
Animal a = new Dog [Fish]; // The manifestation of Polymorphism
5. Notes for using polymorphism:
1. In the case of polymorphism: The child parent class has a member variable with the same name. By default, it is a member variable in the parent class accessed.
2. In the case of polymorphism: the sub-parent class has non-static methods with the same name and accesses non-static methods of sub-classes.
3. Polymorphism: The child parent class has a static method with the same name.
4. In the case of polymorphism: the unique member of the subclass cannot be accessed.
Summary: in the case of polymorphism, if a child parent class has members with the same name, all the Members are accessing the parent class, except that non-static methods with the same name are access subclasses.
Caused by java compiler compilation principles
Compile to the left, and run not necessarily to the right
Compile to the left: the java compiler will check whether the reference type contains specified members during compilation. If not, an error will be reported.