Question 127 of 481
1Z0-811 Arrays and Methods Practice Question
Given the code:
public class Test {
public static void change(int[] arr) {arr = new int[]{10, 20};
}
public static void main(String[] args) {int[] arr = {1, 2}; change(arr); System.out.println(arr[0]);
} }
What is the output?
⚠ Common exam trap
Oracle often tests the distinction between modifying an object's state versus reassigning a reference, and the trap here is that candidates mistakenly believe reassigning the parameter inside the method will change the original array reference in the caller.
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
✓
1
In Java, array references are passed by value. Inside the `change` method, the local variable `arr` is reassigned to a new array, but this does not affect the original array reference in `main`. Therefore, `arr[0]` in `main` still refers to the original array element `1`.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
1
Why this is correct
The method creates a new array and assigns it to the local parameter, but this assignment does not change the caller's reference, so arr[0] remains 1.
- ✗
10
Why it's wrong here
10 is from the new array created inside the method, but it is not reflected in the caller's scope.
- ✗
20
Why it's wrong here
Similar to B.
- ✗
Compilation error
Why it's wrong here
The code compiles and runs without error.
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.