Array Creation and Access

AP Computer Science A· difficulty 2/5

int[] a = new int[4];
System.out.println(a[0] + " " + a[3]);

What is printed?

  • A

    null null

  • B

    0 0

    check_circle
  • C

    ArrayIndexOutOfBoundsException

  • D

    1 1

Explanation

new int[4] creates an int array of length 4 with default values. The default for int is 0, so all elements start as 0.

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

Related questions