1Z0-811 Java Basics and Syntax Practice Question
Exhibit
public class Test {
public void print(String s) { System.out.println("String"); }
public void print(Object o) { System.out.println("Object"); }
public static void main(String[] args) {
Test t = new Test();
t.print(null);
}
}Refer to the exhibit. What is the output?
⚠ Common exam trap
The trap here is that candidates may not understand Java's method overloading resolution and assume the method with Object parameter will be called, leading them to choose 'Object', or they might think the code will not compile or will throw a runtime exception.
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
✓
String
The code exhibits method overloading with one method accepting an Object parameter and another accepting a String parameter. When a String argument is passed, Java selects the most specific matching method, which is the String version, so the output is 'String'.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Runtime error
Why it's wrong here
No runtime error occurs.
- ✗
Compilation error
Why it's wrong here
The code compiles; there is no ambiguity because String is more specific.
- ✗
Object
Why it's wrong here
String is more specific, so it is chosen over Object.
- ✓
String
Why this is correct
The more specific overload (String) is chosen.
Go deeper
Related to this question
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 →
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.