Courseiva
Arrays and MethodshardMultiple ChoiceObjective-mapped

1Z0-811 Arrays and Methods Practice Question

Exhibit

Refer to the exhibit.

public class ArrayReturn {
    public static int[] getArray() {
        int[] a = {1, 2, 3};
        return a;
    }
    public static void main(String[] args) {
        int[] b = getArray();
        b[0] = 99;
        for (int v : getArray()) {
            System.out.print(v + " ");
        }
    }
}

What is the output?

⚠ Common exam trap

Oracle often tests the misconception that modifying the loop variable in a for-each loop changes the array, leading candidates to incorrectly expect the value 99 to appear in the output.

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 2 3

The code defines a method getArray() that returns a new array containing {1, 2, 3}. Two calls to getArray() each return a separate array, and the loop prints the elements of the first array as "1 2 3 ". Option B is correct because the for-each loop iterates over the array in order and prints each element.

Answer analysis

Option-by-option breakdown

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

  • Compilation error

    Why it's wrong here

    The code compiles and runs without error.

  • 1 2 3

    Why this is correct

    Each call to getArray() creates a new array with values {1,2,3}. The modification of b affects the first array, but the second call returns a separate array, so the output is 1 2 3.

  • 1 2 3 99

    Why it's wrong here

    No extra numbers are printed; the for-each iterates over the three elements returned by getArray().

  • 99 2 3

    Why it's wrong here

    This would happen if the second call returned the same array object, but it does not.

About these practice questions

Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.