Question 345 of 509
Arrays and MethodshardMultiple ChoiceObjective-mapped

Quick Answer

The answer is 99. This output occurs because Java passes object references by value, meaning the method receives a copy of the array reference, but both the original and the copy point to the exact same array object in heap memory. When you modify array elements inside the method using `arr[0] = 99`, you are directly altering the content of that shared array object, so the change is visible through the original reference `myArray` after the method returns. On the Oracle Java Foundations 1Z0-811 exam, this concept tests your understanding of pass-by-value semantics with reference types, a frequent source of confusion for beginners who mistakenly think the array itself is copied. A common trap is assuming that reassigning the array parameter inside the method (e.g., `arr = new int[3]`) would affect the caller—it does not, because only the reference copy is changed. Remember the memory tip: "Reference copy, same object; element changes stick, reassignment won't."

1Z0-811 Arrays and Methods Practice Question

This 1Z0-811 practice question tests your understanding of arrays and methods. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

A method 'public static void modifyArray(int[] arr) { arr[0] = 99; }' is called with 'int[] myArray = {1,2,3}; modifyArray(myArray); System.out.println(myArray[0]);'. What is the output?

Question 1hardmultiple choice
Full question →

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

99

In Java, when an array is passed to a method, the reference to the array is passed by value. This means the method receives a copy of the reference, but both the original and the copy point to the same array object in heap memory. Therefore, modifying an element of the array inside the method (arr[0] = 99) directly changes the original array's content. When myArray[0] is printed after the call, it outputs 99.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • 99

    Why this is correct

    The method modifies the array element.

    Related concept

    Read the scenario before looking for a memorised answer.

  • 1

    Why it's wrong here

    The array is modified, so the value changes.

  • 0

    Why it's wrong here

    Not the default value; the original element is overwritten.

  • Compilation error

    Why it's wrong here

    The code compiles fine.

Common exam traps

Common exam trap: answer the scenario, not the keyword

Oracle often tests the misconception that Java passes objects by value in the sense that the object itself is copied, leading candidates to incorrectly think that changes inside a method do not affect the original array.

Detailed technical explanation

How to think about this question

Under the hood, Java stores array objects in heap memory, and the variable myArray holds a reference (a memory address). When passed to modifyArray, the reference value is copied onto the stack for the method, but both references point to the same heap object. This is often called 'pass-by-reference-value' and is a common source of confusion. In real-world scenarios, this behavior is crucial for performance when modifying large arrays in-place, such as in sorting algorithms or data transformation pipelines.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A practitioner preparing for the 1Z0-811 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related 1Z0-811 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free 1Z0-811 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this 1Z0-811 question test?

Arrays and Methods — This question tests Arrays and Methods — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: 99 — In Java, when an array is passed to a method, the reference to the array is passed by value. This means the method receives a copy of the reference, but both the original and the copy point to the same array object in heap memory. Therefore, modifying an element of the array inside the method (arr[0] = 99) directly changes the original array's content. When myArray[0] is printed after the call, it outputs 99.

What should I do if I get this 1Z0-811 question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

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 →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

2 more ways this is tested on 1Z0-811

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Consider the following code that attempts to swap the first two elements of an array using a method: public static void swap(int[] arr) { int temp = arr[0]; arr[0] = arr[1]; arr[1] = temp; } public static void main(String[] args) { int[] values = {1, 2}; swap(values); System.out.println(values[0] + " " + values[1]); } What is the output?

easy
  • A.2 1
  • B.The code does not compile.
  • C.1 2
  • D.A runtime exception occurs.

Why A: Option A is correct because the `swap` method receives a reference to the array, so modifications to its elements (via index assignment) affect the original array. After swapping, `values[0]` becomes 2 and `values[1]` becomes 1, producing the output "2 1".

Variation 2. A method 'public static void modify(int[][] matrix) { matrix[0][0] = 99; }' is called with 'int[][] values = {{1,2},{3,4}}; modify(values);'. What is the value of values[0][0] after the call?

hard
  • A.99
  • B.Exception
  • C.1
  • D.0

Why A: Option A is correct because Java passes object references by value. When 'modify(values)' is called, the reference to the 2D array is copied into the method parameter 'matrix'. Since 'matrix' points to the same array object, modifying 'matrix[0][0]' directly changes the original array's element, so 'values[0][0]' becomes 99.

Last reviewed: Jun 30, 2026

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.

Loading comments…

Sign in to join the discussion.

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.