Features of non-static member functions in polymorphism: ① during compilation: see whether calling methods exist in the class to which referenced variables belong. If yes, the compilation is successful; otherwise, the compilation fails. ② during runtime: see whether methods are called in the class to which the object belongs. Features of the non-static member functions in polymorphism:
① During compilation: see whether calling methods exist in the class to which the referenced variable belongs. If yes, the compilation is successful; otherwise, the compilation fails;
② Runtime: see whether methods are called in the class to which the object belongs.
--------------------------------------------------
// In short: when a member function is called, compile the function to the left and run the function to the right. //
--------------------------------------------------
2. features of member variables with the same name in polymorphism: (ps: not verified by different names)
For compilation and running, refer to the class to which the referenced variable belongs)
3. characteristics of static member functions in polymorphism:
For compilation and running, refer to the class to which the referenced variable belongs)
Example:
Class Fu {int num = 1; public void method1 () {System. out. println ("fu_1");} public void method3 () {System. out. println ("fu_3");} // The static method (including variables) does not belong to the object. it is bound to the class to which it belongs, public static void method4 () {System. out. println ("fu_4") ;}} Class Zi extends Fu {int num = 2; public void method1 () {System. out. println ("zi_1");} public void method2 () {System. out. println ("zi_2");} public static void method4 () {System. out. println ("zi_4") ;}} Class Duotaitest {public static void main (String [] args) {Fu f = new Zi (); f. method1 (); // f. method2 (); if this line of code exists, compilation fails. f is not used in the Fu class. method3 (); f. method4 (); System. out. println (f. num); Zi z = new Zi (); System. out. println (z. num);}/* running result: zi_1fu_3fu_4 // The static method cannot be overwritten by the quilt class. if you want to call the static method in the subclass (this is generally not used, but will be used for the interview) zi. method4 (class name. method name) 12 */}