1Z0-811 Arrays and Methods Practice Question
Exhibit
javac Test.java
Test.java:5: error: reference to print is ambiguous
print(null);
^
both method print(String[]) in Test and method print(String...) in Test matchRefer to the exhibit. Which overloaded methods cause this compilation error?
⚠ Common exam trap
The trap here is that candidates mistakenly think varargs and arrays are distinct types for overloading, but Java treats them identically after compilation, so defining both `print(String[])` and `print(String...)` causes a duplicate method error.
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
✓
public void print(String[] s) and public void print(String... s)
Java does not allow overloading methods that differ only by the use of a varargs parameter and an array parameter of the same type. Both `public void print(String[] s)` and `public void print(String... s)` have the same method signature after erasure — they both accept a `String[]` at the bytecode level — causing a compilation error due to ambiguity.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
public void print(String s) and public void print(String[] s)
Why it's wrong here
This combination is valid because the first method takes a single String and the second takes a String array; they have different parameter types, so no compilation error.
- ✗
public void print(String s) and public void print(String... s)
Why it's wrong here
This combination is valid because a single String parameter and a varargs String parameter are different signatures; the compiler can distinguish between them, so no error.
- ✓
public void print(String[] s) and public void print(String... s)
Why this is correct
This combination causes a compilation error because a String array parameter and a String varargs parameter are considered the same after type erasure; the compiler sees them as duplicate methods.
- ✗
public void print(Object... o) and public void print(String... s)
Why it's wrong here
This combination is valid because the varargs are of different types (Object and String), so the method signatures are distinct; no compilation error.
Go deeper
Related to this question
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 →
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.