Instances of polymorphic in Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.