File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marcus exam 3 # 26

 
Stewart Henry
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question is:

The correct answer is given as 2. I don't believe that this is correct, because only elements within arrays are always initialized, the arrays themselves are not always initialized. For example this code:

gives the familiar compile error - Variable arr may not have been initialized.
 
Manish Hatwalne
Ranch Hand
Posts: 2591
Android Firefox Browser Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stewart,
It gives compiler error because array has not been created.
Try this -
<pre>
int arr[] = new int[10];
System.out.println(arr);
System.out.println(arr[9]);
</pre>
This creates an array of 10 integers, and initializes all of them to 0. This compiles and prints correctly.
HTH,
- Manish
[This message has been edited by Manish Hatwalne (edited October 01, 2001).]
 
laxmikant shimpi
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the difference is between creation and declaration ...
Arrays are used with these three steps.
1. Declare an Array
2. Construct an array
3. Use an array or a single array element..
now what you did in your code was just the declaration ....
and what Marcus says was creation ... perhaps it should be construction ....
may be the wording should be

2) Arrays are initialized to default values wherever they are created ( Constructed )
this should potentially reduce your chances of understand the answer...
I hope this works fine with you .....
Please reply any one with different opinion ...
Laxmikant


------------------
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declaring an array doesn't actually create an array. All it does is create a pointer that can hold an Array object. The array itself is created until a "new" is executed.
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just changed the text to the following, what do you think? I want my questions to be unambiguous as well as correct.
2) Arrays elements are initialized to default values wherever they are created with a call to new
------------------
http://www.jchq.net Mock Exams, FAQ, Tutorial, Links, Book reviews
=================================================
Almost as good as JavaRanch
=================================================
 
Stewart Henry
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Marcus, I like that much better.
 
marilyn murphy
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about
2) Arrays elements are initialized to default values wherever an array is created using the keyword new.
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
New wording, thanks for all the feedback.....
2) Arrays elements are initialized to default values wherever they are created using the keyword new.
------------------
http://www.jchq.net Mock Exams, FAQ, Tutorial, Links, Book reviews
=================================================
Almost as good as JavaRanch
=================================================
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marcus Green:
New wording, thanks for all the feedback.....
2) Arrays elements are initialized to default values wherever they are created using the keyword new.

It is ambiguous wether "they" referrs to "arrays" or "array's elements."
2) Array's elements are initialized to default values whenever arrays are created using the keyword new.
English, such a funny language...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic