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)