<< Chapter < Page | Chapter >> Page > |
What output is produced by program shown in Listing 14 ?
Listing 14 . Listing for Question 14. |
---|
public class Ap062{
public static void main(String args[]){new Worker().doArrays();
}//end main()}//end class definition
class Worker{public void doArrays(){
Object[]A = new Object[2];A[0] = new MyClass(1.0);A[1] = new MyClass(2.0);System.out.println(A[0].getData() + " " +A[1].getData());}//end doArrays()
}// end classclass MyClass{
private double data;public MyClass(double data){this.data = data;
}//end constructorpublic double getData(){return data;
}//end getData()}// end MyClass |
What output is produced by program shown in Listing 15 ?
Listing 15 . Listing for Question 15. |
---|
public class Ap063{
public static void main(String args[]){new Worker().doArrays();
}//end main()}//end class definition
class Worker{public void doArrays(){
Object[]A = new Object[2];A[0] = new MyClass(1.0);A[1] = new MyClass(2.0);System.out.println(((MyClass)A[0]).getData() + " "+ ((MyClass)A[1]).getData());}//end doArrays()
}// end classclass MyClass{
private double data;public MyClass(double data){this.data = data;
}//end constructorpublic double getData(){return data;
}//end getData()}// end MyClass |
I recommend that you open another copy of this document in a separate browser window and use the following links to easilyfind and view the listings while you are reading about them.
This section contains a variety of miscellaneous information.
Financial : Although the Connexions site makes it possible for you to download aPDF file for this module at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, youshould be aware 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 ofthe module.
In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale onAmazon.com showing me as the author. I neither receive compensation for those sales nor do I know who does receive compensation. If youpurchase such a book, please be aware that it is a copy of a module that is freely available on cnx.org and that it was made andpublished without my prior knowledge.
Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?