A

Admin • 828.03K Points
Coach

Q. What is the output of the following code?

Code:
int[] arr = new int[]{1, 2, 3, 4, 5};
System.out.println(arr[5]);
  • (A) 0
  • (B) null
  • (C) Compiler error
  • (D) ArrayIndexOutOfBoundsException
  • Correct Answer - Option(D)
  • Views: 9
  • Filed under category Java
  • Hashtags:

Explanation by: Admin
The array index 5 is out of bounds, since the array has only 5 elements.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.