<< Chapter < Page Chapter >> Page >
Disclaimers:

Financial : Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.

I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.

In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. Ineither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please beaware that it is a copy of a module that is freely available on cnx.org and that it was made and published withoutmy prior knowledge.

Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.

Complete program listing

A complete listing of the program is provided in Listing 17 .

Figures

Figure 1 - Class files produced by the program.
A$1$B.class A.classInnerClasses07.class X.classY.class
Figure 2 - Screen output.
In xstr for A, aTime = 10
Figure 3 - Screen output.
In meth, methTime = 40
Figure 4 - Screen output.
---------------------- Instantiate first B-objectIn xstr for B, bTime = 70 Delay and instantiate second B-objectIn xstr for B, bTime = 100
Figure 5 - Screen output.
---------------------- Display first B-Object-1- In showB, private bTime = 70In showB, private aTime = 10 In showB, final methTime = 40In showB, protected xVar = 1000 In showB, protected yVar = 2000In showB, class name = A$1$B
Figure 6 - Screen output.
-2- In showA, aTime = 10In showA, xVar = 1000 In showA, class name = A
Figure 7 - Screen output.
-3- In showB, bTime = 70In showB, aTime = 10
Figure 8 - Screen output.
-4- toString in class B, bTime = 70toString in class Y, yVar = 2000
Figure 9 - Screen output.
---------------------- Display second B-Object-1- In showB, private bTime = 100In showB, private aTime = 10 In showB, final methTime = 40In showB, protected xVar = 1000 In showB, protected yVar = 2000In showB, class name = A$1$B -2-In showA, aTime = 10 In showA, xVar = 1000In showA, class name = A -3-In showB, bTime = 100 In showB, aTime = 10-4- toString in class B, bTime = 100toString in class Y, yVar = 2000

Listings

Listing 1 - The controlling class named InnerClasses07.
public class InnerClasses07{ static long baseTime = new Date().getTime();public static void main(String[] args){new A().meth(); }//end main}//end class InnerClasses07
Listing 2 - The class named X.
class X{ protected int xVar = 1000;}//end class X
Listing 3 - The class named Y.
class Y{ protected int yVar = 2000;public String toString(){ return "toString in class Y, yVar = " + yVar;}//end overridden toString }//end class Y
Listing 4 - Beginning of the class named A.
class A extends X{ private long aTime = new Date().getTime() -InnerClasses07.baseTime; A(){//constructorSystem.out.println( "In xstr for A, aTime = " + aTime);}//end constructor

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