<< Chapter < Page Chapter >> Page >
Listing 4 - Constructor for class A.
A(int val){//top-level class constructor aVar = val;objCntA++;//Increment object counter //Record the number of the object being// instantiated objNumber = objCntA;System.out.println( "In xstr for A, objCntA = " + objCntA);}//end constructor
Listing 5 - Beginning of the member class named B.
class B{//member class of A private int bVar;private int objNumber = 0;
Listing 6 - Constructor for class B.
B(int val){//constructor bVar = val;//Increment static variable in top-level // class named AA.objCntB++; //Record the number of the object being// instantiated objNumber = objCntB;System.out.println( "In xstr for B, objCntB = " + objCntB);}//end constructor
Listing 7 - Beginning of the member class named C.
class C extends X{//member class of B private int cVar;private A refToA; private B refToB;private String className = "C"; private int objNumber = 0;
Listing 8 - Beginning of constructor for class C.
C(int val){//constructor cVar = val;//Increment the object counter in the // top-level class named A.A.objCntC++; objNumber = A.objCntC;System.out.println( "In xstr for C, objCntC = "+ A.objCntC);
Listing 9 - The private member class named D.
private class D{//member class of C D(){//constructorSystem.out.println( "Construct obj of private class D.");System.out.println( " Private class file name: "+ this.getClass().getName()); }//end constructor}//end class D
Listing 10 - More constructor code for class C.
new D();
Listing 11 - More constructor code for class C.
refToA = new A(10); refToB = new B(20);}//end constructor
Listing 12 - The method named bShow.
private void bShow(){ System.out.println("In bShow, bVar = " + bVar); System.out.println("In bShow, objNumber = " + objNumber); aShow();}//end bShow
Listing 13 - The method named aShow.
private void aShow(){ System.out.println("In aShow, aVar = " + aVar); System.out.println("In aShow, objNumber = " + objNumber); }//end aShow
Listing 14 - Beginning of the cShow method.
public void cShow(){ System.out.println("-1-");//separatorSystem.out.println( "In cShow, objNumber = " + objNumber);System.out.println( "In cShow, cVar = " + cVar);
Listing 15 - More cShow method code.
System.out.println("-2-");//separator bShow();
Listing 16 - Call the aShow method.
System.out.println("-3-");//separator aShow();
Listing 17 - More cShow method code.
System.out.println("-4-");//separator System.out.println(getClass().getName());System.out.println( this.getClass().getName());System.out.println( C.this.getClass().getName());System.out.println( B.C.this.getClass().getName());System.out.println( A.B.C.this.getClass().getName());
Listing 18 - More cShow method code.
System.out.println("-5-");//separator System.out.println(B.this.getClass().getName()); System.out.println(A.B.this.getClass().getName());

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask