Which of the following creates a jagged array in Java?

  1. int[][] arr = new int[2][2];
  2. int[][] arr = new int[2][];
  3. int[][] arr = {{1, 2}, {3, 4}};
  4. int[][] arr = new int[][];
Correct answer int[][] arr = new int[2][];

Explanation

Option B creates an array of 2 rows without specifying column size (jagged array).

Update: Admin added a tag on this question

Topics

By Admin · · 22 views