Question 52

Which of the following Java statements declare and allocate a 2-dimensional array of integers with four rows and five columns.

  1. Aint array [][] = new int [5][4];
  2. Bint array [4][5];
  3. Cint array [5][4];
  4. Dint array [][] = new int [4][5];
Show answerHide answer

Correct answer: (D) int array [][] = new int [4][5];

Explanation

In Java, new int[4][5] creates 4 rows and 5 columns. Declarations like int array[4][5] are not valid Java, and [5][4] has the dimensions reversed.

From DSSSB TGT Computer Science Practice Set 1

This is question 52 of DSSSB TGT Computer Science Practice Set 1. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.