Understanding whether inner classes will be overwritten (thinking in Java)

Source: Internet
Author: User

1  PackageThinkingdemo;2 /*3  * 4 * About nested class coverage issues5  * 6  */7 classEGG2 {8     protected classyolk{9          Publicyolk () {TenSystem.out.println ("Egg2.yolk ()"); One         } A          Public voidf () { -System.out.println ("Egg2.yolk.f ()"); -         } the     } -     PrivateYolk y =Newyolk (); -      PublicEgg2 () { -System.out.println ("New Egg2 ()"); +     } -      Public voidinsertyolk (Yolk yy) { +y =yy; A     } at      Public voidg () { - y.f (); -     } - } - classBigEgg2extendsEGG2 { -      Public classYolkextendsEgg2.yolk { in          Publicyolk () { -System.out.println ("Bigegg2.yolk ()"); to         } +          Public voidf () { -System.out.println ("Bigegg2.yolk.f ()"); the         } *     } $      PublicBigEgg2 () {Panax NotoginsengInsertyolk (Newyolk ()); -     } the } +  Public classNestclassoverride { A      Public Static voidMain (string[] args) { theEGG2 e2 =NewBigEgg2 (); + e2.g (); -     } $}


Execution Result:

Egg2.yolk ()

New Egg2 ()

Egg2.yolk ()

Bigegg2.yolk ()

Bigegg2.yolk.f ()

This is available: Inner classes are not overwritten

Understanding whether inner classes will be overwritten (thinking 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.