In Java development, Java developers suggested that, as little as possible, the inner class should be used to bring the inner class to the class he was in and generate a separate class.
directly to the code:
Copy Code code as follows:
Package com.b510;
/**
* Calls between internal classes
*
* @author Hongten
*
* @time 2012-3-19 2012
*/
public class Innerclasstest {
public static void Main (string[] args) {
This is an example of innerclasstest.
Innerclasstest innerclasstest = new Innerclasstest ();
Innerclasstest.sayhelloworld ();
This is an instance of Class A
Innerclasstest.a ia = innerclasstest.new A ();
Ia.asayhello ();
This is an example of INNERCLASSB.
INNERCLASSTEST.A.INNERCLASSB IAB = Ia.new innerclassb ();
Iab.bsayhello ();
This is an example of INNERCLASSC.
INNERCLASSTEST.A.INNERCLASSB.INNERCLASSC iabc = Iab.new innerclassc ();
Iabc.csayhello ();
This is an example of INNERCLASSD.
INNERCLASSTEST.A.INNERCLASSD iad = ia.new innerclassd ();
Iad.dsayhello ();
This is an example of Innerclasse.
Innerclasstest.a.innerclassb.innerclassc.innerclasse IABCE = Iabc.new Innerclasse ();
Iabce.esayhello ();
Of course, when we call Innerclasse, we can write this.
Innerclasstest.a.innerclassb.innerclassc.innerclasse e = new Innerclasstest (). New A (). New Innerclassb (). New INNERCLASSC (). New Innerclasse ();
System.out.println ("====================== separator = = = =");
E.esayhello ();
}
Methods in the class Innerclasstest
public void SayHelloWorld () {
System.out.println ("I am test,helloworld!");
}
/**
* Define Class A, he is the inner class of the Innerclasstest class
*/
Class A {
Methods in Class A
public void Asayhello () {
System.out.println ("I am a,helloworld!");
}
/**
* Define INNERCLASSB class, he inherits Class A
*/
Class Innerclassb extends A {
Methods in the class INNERCLASSB
public void Bsayhello () {
System.out.println ("I am B,helloworld");
}
/**
* Define INNERCLASSC class, he is the inner class of INNERCLASSB
*/
Class INNERCLASSC {
Methods in the class INNERCLASSC
public void Csayhello () {
System.out.println ("I am c,helloworld!");
}
/**
* Define Innerclasse class, he is the inner class of INNERCLASSC
*/
Class Innerclasse {
Methods in the class Innerclasse
public void Esayhello () {
System.out.println ("I am e,helloworld!");
}
}
}
}
/**
* Define INNERCLASSD class, he is the internal class of a
*/
Class INNERCLASSD {
Methods in the class INNERCLASSD
public void Dsayhello () {
System.out.println ("I am d,helloworld!");
}
}
}
}
Operation Effect:
Copy Code code as follows:
I am test,helloworld!
i am a,helloworld!
i am B,helloworld
i am c,helloworld!
i am d,helloworld!
i am e,helloworld!
====================== Separator = =
i am e,helloworld!