// 2004-9-18 Internal Summary:
1 The nesting of the internal class can understand the classic chain relationship. When constructing an internal class (non-Static) instance, an instance of the direct outer layer class is passed as a parameter, and the example of the outer layer class is also Constructs an example of its outer class, so is a chain relationship, the interior class can use an example of all outer layers, and the outer layer cannot use the inner layer, Application A.THIS (outermost layer) Class example), abcthis (instance of an outer layer in the chain).
Class theouter {class kk = 100;}} class aa {class bb {INT jj = 10; Class CC {{INT ff = theouter.aa.bb.this.jj; // Unable to access directly GG is not in the chain system system.out.println (ff);}}}}}
2 Create an internal NEW AA (). New bb (). New () cc is actually calling the outer class instance. NEW This layer constructor () If the internal class is Static's uncommon instances of the outer class STATIC Nested Internal Class AA.BB.CC Test = New Aa.bb.cc ();
3CLASS A0 {Class B0 {}}
Class VVV {Class FF EXTENDS A0.B0 {// FF This is not an internal class also row ff (a0 kk) {kk.super ();}}} inherited SUPER () to call the outer class of the parent class
4CLASS DD {void print () {system.out.println ("DD.Println is there");} Class KK {KK (INT i) {} class cc {void pp () {system.out.println ("* * *** ");} void ddpp () {dd.this.print ();}}}}
Class aa {public static void main (string agrs []) {dd.kk.cc test = new DD (). New kk (10) .new cc (); test.ddpp ();}} can be in the class Use outer class, but if the handle generating an instance does not provide the function of accessing the upper layer class.
5 this refers to the instance of this class
6 Default newclass cc {{new test ();} class kk {{system.out.println ("there});}} class test {{new kk ();} Class KK {{system.out. Println ("there Test_KK");}}}} can be used directly, New's range can be direct outer layer .th.new and this.new But if the inner layer and the outer layer appear to be internal priority
7 // When there is a chain relationship, you should pay attention to the class vv {class bb {} //! Class KK {} //! Class KK {// Class vv {} will be wrong Class BB {} //! This will not be wrong. }
8CLASS A0 {Class B0 {}}
Class vvv {class ff extends A0.B0 {// is not internal class also row FF (A0 KK) {kk.super ();}}} Inherited SUPER () 9 of the external class of the internal class to call the parent class anonymous Internal Class Interface OO {// oo (int G) {} int K = 10; void pt ();}
Class PP {PP (INT G) {} int GET () {Return 100;}} Class ME {/ * interface} {void Pt ();} * / class kk {oo testmed () {Final INT i = 10; INT g = 100; return new {INT KK; {// Use the outside thing to be named FINAL // Inherit Interface Internal priority // Anonymous internal class does not construct a function, only block, initialize KK = i K;} public void pt () {system.out.println (kk);}};} PP testmed0 () {RETURN NEW PP (10) {// Inherited Self-class public int GET () {Return Super.Get ) * 10;}};}}} Anonymous internal class can inherit the self-interface or inherit self-class, inheriting the self-class constructor can have parameters.
10CLASS BF {interface kk {} class aa {// interface can nest in the interface (unrestricted), or nested in the top, below // interface gg {}}}}}}}}}}