Array Creation and Access

AP Computer Science A· difficulty 2/5

int[] a = {10, 20, 30, 40};
System.out.println(a[2]);

What is printed?

  • A

    30

    check_circle
  • B

    20

  • C

    40

  • D

    2

Explanation

Arrays are 0-indexed, so a[0]=10, a[1]=20, a[2]=30, a[3]=40. Index 2 is the third element, 30.

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

Related questions