🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Arrays: all 10 questions

Quiz: Java Arrays · Question 7 of 10

int[] a = new int[5]; What happens at a[a.length] = 1;?

int[] a = new int[5]; What happens at a[a.length] = 1;?

  1. A.The array grows to 6 elements
  2. B.Compile error
  3. C.The value is stored in the last element
  4. D.ArrayIndexOutOfBoundsException at run time
Answer & explanation

Correct answer: ArrayIndexOutOfBoundsException at run time

Valid indexes are 0 to 4. The compiler does not check index values, so the error appears when the line runs.

Can you get the rest right without peeking?

Take the timed Quiz: Java Arrays quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →