Hi All Which code fragments will succeed in initializing a two-dimensional array named tab with a size that will cause the expression tab[3][2] to access a valid element? CODE FRAGMENT A: int[][] tab = { { 0, 0, 0 }, { 0, 0, 0 } }; CODE FRAGMENT B: int tab[][] = new int[4][]; for (int i=0; i<tab.length; i++) tab[i] = new int[3];> CODE FRAGMENT C: int tab[][] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; CODE FRAGMENT D: int tab[3][2]; CODE FRAGMENT E: int[] tab[] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0} }; a.Code A b.Code B c.Code C d.Code D e.Code E I do not know the correct answers for it Please help
SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
pardha
Greenhorn
Joined: Jun 18, 2000
Posts: 11
posted
0
I guess answer is "E" ,you require 4 arrays of 3 elements each. E declares and initialises correctly. Correct me ,If I am wrong.
latha
Greenhorn
Joined: Jul 17, 2002
Posts: 14
posted
0
Yaa, I agree with Pardha. The answer is E. To access tab[3][2] elament, tab[][] should have min of [4][3] array.