<< Chapter < Page Chapter >> Page >

The end of the program

At this point, the main method terminates causing the program to terminate.

Run the program

I encourage you to copy the code from Listing 6 , compile it and execute it. Experiment with the code, making changes, and observing the results of yourchanges. Make certain that you can explain why your changes behave as they do.

Summary

You learned about the following OOP concepts, among others in this module.

  • Multiple levels of indirection
  • A one-element array of type Object
  • Storing a reference to an object in an array element as type Object
  • An anonymous object
  • Passing a reference to a subclass object as type Object
  • Downcasting an incoming object reference to access a method

What's next?

You will learn how to use nested loops to process pixels on a row and column basis in the next module.

While not a requirement of the course, you can select the following links to view optional online video lectures on the material in thismodule.

Miscellaneous

This section contains a variety of miscellaneous information.

Housekeeping material
  • Module name: Java OOP: Indirection, Array Objects, and Casting
  • File: Java3010.htm
  • Published: 08/02/12
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 listings

A complete listing of the program discussed in this module is shown in Listing 6 below.

Listing 6 . Complete program listing.
/*File Prob05 Copyright 2001, R.G.Baldwin Rev 12/16/08*********************************************************/ import java.util.*;class Prob05{ public static void main(String[]args){ Random generator = new Random(new Date().getTime());int randomNumber = (byte)generator.nextInt(); Object[]objRef = {new Prob05MyClassA(randomNumber)}; System.out.println(new Prob05MyClassB().getDataFromObj(objRef[0]));System.out.println(randomNumber); }//end main}//end class Prob05 //======================================================//class Prob05MyClassA extends Prob05{ private int data;public Prob05MyClassA(int inData){ System.out.println("Prob05");System.out.println("Dick"); data = inData;}//end constructor public int getData(){return data; }//end getData()}//end class Prob05MyClassA //======================================================//class Prob05MyClassB{ Prob05MyClassB(){System.out.println("Baldwin"); }//end constructorpublic int getDataFromObj(Object refToObj){ return ((Prob05MyClassA)refToObj).getData();}//end getDataFromObj() }//end class Prob05MyClassB

-end-

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