Author Topic:   Barry Boones Mock Exam newtest.html
Jerson Chua
ranch hand
posted April 02, 2000 12:11 AM             
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 since is not working.

Milind
ranch hand
posted April 02, 2000 07:21 AM             
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

maha anna
bartender
posted April 02, 2000 09:46 AM             
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
posted April 02, 2000 07:20 PM             
thanks millind and maha anna.

|