Vimal Panchal
Vimal Panchal

Reputation: 301

Java valid declarations of a two-dimensional array

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:

  1. int[][] array2D;
  2. int[2][2] array2D;
  3. int array2D[];
  4. int[] array2D[];
  5. 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.

  1. Am I right?
  2. Is int[] array2D[] recommended in programming?

Upvotes: 1

Views: 2650

Answers (1)

Akshay
Akshay

Reputation: 1161

The answer to this seems to be both options 1 and 4.

int[][] array2D 

is a standard way to declare a 2-d int array.

Although int[] array2D[]; it is not a good practice it will work and will be a valid declaration.

Upvotes: 5

Related Questions