Which syntax is incorrect to initialize a two-dimensional array in Java?

2024

Which syntax is incorrect to initialize a two-dimensional array in Java?

  1. A.

    int myarr[][] = new int[3][4];

  2. B.

    int[][] myarr = {{1, 2, 3}, {4, 5, 6}};

  3. C.

    int[][] myarr = new int[3][4];

  4. D.

    int myarr = new int[3][4];

  5. E.

    Question not attempted

Attempted by 65 students.

Show answer & explanation

Correct answer: D

A two-dimensional int array variable must be declared as int[][] or int[][]. The syntax 'int myarr = new int[3][4];' assigns an array to a single int variable, so it is incorrect.

Explore the full course: Up Lt Grade Assistant Teacher 2025