int[] a = {1, 2, 3};
System.out.println(a[3]);What happens when this code runs?
- Acheck_circle
ArrayIndexOutOfBoundsException is thrown
- B
It prints 3
- C
It prints 0
- D
NullPointerException is thrown
Explanation
Valid indices for an array of length 3 are 0, 1, and 2. Accessing a[3] throws ArrayIndexOutOfBoundsException at runtime.