Class cat {public void miao () {system. out. println ("I am a cat") ;}} class whitecat extends cat {public void miao () {system. out. println ("I Am a whitecat");} public class test {/*** @ Param ARGs */public static void getcat (CAT) {system. out. println ("cat ----"); cat. miao ();} public static void getcat (whitecat) {system. out. println ("whitecat ----"); whitecat. miao ();} public static void main (string [] ARGs) {// todo auto-generated method stubcat cat = new CAT (); CAT whitecat = new whitecat (); whitecat whitecat1 = new whitecat (); getcat (CAT); getcat (whitecat); getcat (whitecat1 );}}
The output is
Cat ----
I am a cat
Cat ----
I am a whitecat
Whitecat ----
I am a whitecat
--------------------------------------------------------
Conclusion: There are multiple overload methods, which can be selected during the call. If the parameters of different methods are inherited, the selection is determined during the compilation period, which is determined by the reference type, instead of Object Type
In the method body, calling the polymorphism method will return to "normal ".