2D Arrays: Creation and Access

AP Computer Science A· difficulty 4/5

int[][] m = {{1, 2, 3}, {4, 5, 6}};
System.out.println(m[2][1]);

What is the result?

  • A

    3

  • B

    5

  • C

    ArrayIndexOutOfBoundsException

    check_circle
  • D

    6

Explanation

The array has 2 rows (indices 0, 1). Accessing m[2] throws ArrayIndexOutOfBoundsException.

Want 10 more like this — adaptive to your weak spots?

Related questions