1 Public classCF {2 3 /**4 * Actually this involves the priority problem of method invocation,5 * Priority levels are from high to Low: This.show (O), Super.show (O), This.show (Super) O, Super.show (Super) O. 6 */7 Public Static voidMain (string[] args) {8 9A A1 =NewA ();TenA A2 =NewB (); Oneb b =NewB (); Ac C =NewC (); -D d =NewD (); -System.out.println (A1.show (b));//①a and A theSystem.out.println (A1.show (c));//②a and A -System.out.println (A1.show (d));//③a and D -System.out.println (A2.show (b));//④b and A -System.out.println (A2.show (c));//⑤b and A +System.out.println (A2.show (d));//⑥a and D -System.out.println (B.show (b));//⑦b and B +System.out.println (B.show (c));//⑧b and B ASystem.out.println (B.show (d));//A and D at } - } - - classA { - PublicString Show (D obj) { - return("A and D"); in } - to PublicString Show (A obj) { + return("A and a"); - } the } * $ classBextendsA {Panax Notoginseng PublicString Show (B obj) { - return("B and B"); the } + A PublicString Show (A obj) { the return("B and A"); + } - } $ $ classCextendsB { - } - the classDextendsB { -}
Copy to Google TranslateTranslation Results
Search
Copy
Instances of polymorphic in Java