Which of the following Java statements declare and allocate a 2-dimensional…
2017
Which of the following Java statements declare and allocate a 2-dimensional array of integers with four rows and five columns?
Answer: D. int array[][] = new int[4][5]; — In Java: Array size is specified only during object creation, not in declaration. new int[4][5] creates a 2D array with 4 rows and 5 columns. Options (b) and…
- A.
int array[][] = new int[5][4];
- B.
int array[4][5];
- C.
int array[5][4];
- D.
int array[][] = new int[4][5];
Attempted by 530 students.
Show answer & explanation
Correct answer: D
In Java: Array size is specified only during object creation, not in declaration.
new int[4][5] creates a 2D array with 4 rows and 5 columns.
Options (b) and (c) are invalid because Java does not allow array size in declaration. Option (a) creates 5 rows and 4 columns, which is incorrect.
A video solution is available for this question — log in and enroll to watch it.