Courseiva
Arrays and MethodsmediumMultiple ChoiceObjective-mapped

1Z0-811 Arrays and Methods Practice Question

Exhibit

Refer to the exhibit.

public class VarargsExample {
    public static void main(String[] args) {
        print(1, 2, 3);
        print(new int[]{4, 5, 6});
    }
    public static void print(int... nums) {
        for (int n : nums) {
            System.out.print(n + " ");
        }
    }
}

What is the output?

⚠ Common exam trap

Many exam-takers assume each method call starts on a new line, but the `print` method does not output a newline, so the output is concatenated on the same line.

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 4 5 6

The code uses a varargs method `void print(int... nums)` which accepts zero or more int arguments. When called with `print(1, 2, 3)` and `print(4, 5, 6)`, each call prints the passed integers separated by spaces, resulting in "1 2 3 " and "4 5 6 " on the same line because there is no newline between calls. Thus the output is "1 2 3 4 5 6".

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

    Why it's wrong here

    The second call is also executed, so it prints more.

  • 1 2 3 4 5 6

    Why this is correct

    The first call prints 1 2 3 (with spaces), and the second call prints 4 5 6 on the same line.

  • 1 2 3 4 5 6

    Why it's wrong here

    No newline is printed between calls because the print method does not output a newline.

  • Compilation error: ambiguous method call

    Why it's wrong here

    There is no ambiguity; the method can accept both forms.

About these practice questions

This 1Z0-811 question is part of Courseiva's 481-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.