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
πŸ’¬ Discuss
βœ… Correct Answer: (D) ArrayIndexOutOfBoundsException
Explanation: The array index 5 is out of bounds, since the array has only 5 elements.
Explanation by: Deepak Sahoo
The array index 5 is out of bounds, since the array has only 5 elements.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
350
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Deepak Sahoo
Publisher
πŸ“ˆ
98%
Success Rate