I was going through one App which is suggested for the OCJP exam. I found one question about the two-dimensional array.
Question: Valid declarations of a two-dimensional array.
Options:
int[][] array2D;int[2][2] array2D;int array2D[];int[] array2D[];int[][] array2D[];
My selection: int[][] array2D; and int[] array2D[] but when I submit my answer it tells me that int[] array2D[] is wrong and correct is int[][] array2D[];
I think the int[][] array2D[]; is incorrect answer.
- Am I right?
- Is
int[] array2D[]recommended in programming?
int[] array2D[]is discouraged by the Java Language Specification itself: We do not recommend "mixed notation" in array variable declarations, where bracket pairs appear on both the type and in declarators; nor in method declarations, where bracket pairs appear both before and after the formal parameter list.