Java OCA OCP Practice Question 924

Question

Which of these four array declarations produces a different array than the others?

A.   int[][] nums = new int[2][1]; 
B.   int[] nums[] = new int[2][1]; 
C.   int[] nums[] = new int[][] { { 0 }, { 0 } }; 
D.   int[] nums[] = new int[][] { { 0, 0 } }; 


D.

Note

Options A and B show the braces can be before or after the variable name and produce the same array.

Option C specifies the same array the long way with two arrays of length 1.

Option D is the answer because it is different than the others.

It instead specifies an array of length 1 where that element is of length 2.




PreviousNext

Related