Array Creation and Access

AP Computer Science A· difficulty 2/5

int[] a = {3, 1, 4, 1, 5};
System.out.println(a.length);

What is printed?

  • A

    4

  • B

    6

  • C

    0

  • D

    5

    check_circle

Explanation

The initializer list has 5 elements, so a.length is 5. Note: array length uses the field a.length (no parentheses), not the method a.length().

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

Related questions