Question 58 of 481
1Z0-811 Arrays and Methods Practice Question
Given the method: 'public static void swapFirstTwo(int[] arr) { int temp = arr[0]; arr[0] = arr[1]; arr[1] = temp; }'. What is the effect of calling this method with an array of length 1?
⚠ Common exam trap
Oracle often tests the misconception that a method with a void return type will silently do nothing or leave the array unchanged, when in fact an unchecked array access throws an exception.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
An ArrayIndexOutOfBoundsException is thrown.
The method accesses arr[0] and arr[1] without verifying the array length. When called with an array of length 1, index 1 is out of bounds because valid indices are 0 only. Java performs runtime bounds checking, so an ArrayIndexOutOfBoundsException is thrown.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
An ArrayIndexOutOfBoundsException is thrown.
Why this is correct
Index 1 is out of bounds for length 1.
- ✗
The first element is swapped with itself.
Why it's wrong here
No swap occurs due to exception.
- ✗
A new array with length 2 is returned.
Why it's wrong here
Method returns void.
- ✗
The array remains unchanged.
Why it's wrong here
An exception occurs before any change.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 30, 2026
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.