Which of the following code fragments will throw an ArrayIndexOutOfBoundsException?
Long Answer
Views 32
Answer:
for (int i = 0; i <= args.length; i++) { System.out.print(i); }
Explanation:
The loop runs while i <= args.length, so when i equals args.length, it goes beyond the valid array index, causing an ArrayIndexOutOfBoundsException.
Related Articles:
This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.