• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Barry Boones Mock Exam newtest.html

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Select all valid answers.
String[][] s = new String[10][];
a) This line of code is illegal.
b) s is a two-dimensional array containing 10 rows and 10 columns
c) s is an array of 10 arrays.
d) Each element in s is set to ""
e) Each element in s is uninitialized and must be initialized before it is referenced.
The answer given is c but I think the answer should include e. Why?
You can find this mock exam at http://myhome.shinbiro.com/~neosun/newtest.html since www.learnjava.com is not working.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically a two diamensional array is an array of arrays (nested array) in java. So option C is correct.
Any array can be declared and constructed in a single line as follows:
String[][] s = new String[10][];
When an array is constructed, its elements are automatically initialized exactly as for object member variable. So the option E is incorrect. Numerical elements are initialized to zero, boolean to false and object refrences to null.
Hope this helps !!
Regds,
Milind

 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jerson, Here is my reasoning for each ans
a) This line of code is illegal.
No, It is legal
b) s is a two-dimensional array containing 10 rows and 10 columns
No, The 2nd dim is not specified during array creation
c) s is an array of 10 arrays.
Yes.It is simulated 2 dim array, having 1st dim as 10
d) Each element in s is set to ""
No. Tt is set to null. Not "". Because "" is NOT null. It is an empty String object having 0 length
e) Each element in s is uninitialized and must be initialized before it is referenced.
No. Each element in s , is initialized to null by default. These null refs in s shd further be made to reference a String[] in order to reference an element like this . String s01 = s[0][0]
regds
maha anna

[This message has been edited by maha anna (edited April 02, 2000).]
 
Jerson Chua
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks millind and maha anna.
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic