classfu{intnum = 5; voidmethod1 () {System.out.println ("Fu Method_1"); } voidmethod2 () {System.out.println ("Fu Method_2"); } Static voidmethod4 () {System.out.println ("Fu Method_4"); }}classZiextendsfu{intnum = 8; voidmethod1 () {System.out.println ("Zi Method_1"); } voidmethod3 () {System.out.println ("Zi Method_3"); } Static voidmethod4 () {System.out.println ("Zi Method_4"); }}
Fu f = new Zi ();
System.out.println (f.num);//Print 5
F.METHOD4 ();//Print Zi Method_4
Summarize:
1. 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, compile through, if no compilation fails
At run time: see if there is a method called in the class to which the object belongs
The simple summary is: member function in polymorphic call, compile look to the left, run to see the right
2. In polymorphism, the characteristics of member variables: both compile and run, refer to the left (the class to which the reference variable belongs)
3. In polymorphic, the characteristics of static member functions: both compile and run, refer to the left
Polymorphism (iii)