QuestionQ215

Creating and Using Arrays

Given the following code fragment:

Question Image

What is the result?

  • A An ArrayIndexOutOfBoundsException is thrown at line 10.
  • B 10 : 20 : 30 : 40 : 50 :
  • C An ArrayIndexOutOfBoundsException is thrown at line 14.
  • D The code fails to compile.
Explanation

A Java array with length 5 has valid indices from 0 through 4. Accessing index 5 is outside its bounds, so the assignment at line 14 throws an ArrayIndexOutOfBoundsException.

Community Discussion

No comments yet. Be the first to start the discussion!