1Z0-811 Object-Oriented Programming Practice Question
Exhibit
class Vehicle {
String type = "Vehicle";
}
class Car extends Vehicle {
String type = "Car";
}
public class Test {
public static void main(String[] args) {
Vehicle v = new Car();
System.out.println(v.type);
}
}Refer to the exhibit.
What is 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
✓
Vehicle
In Java, fields are not polymorphic; the reference type determines which field is accessed. v is of type Vehicle, so v.type refers to Vehicle's type field.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
null
Why it's wrong here
The field is initialized.
- ✓
Vehicle
Why this is correct
In Java, fields are not polymorphic; the reference type determines which field is accessed. v is of type Vehicle, so v.type refers to Vehicle's type field.
- ✗
Compilation error
Why it's wrong here
The code compiles successfully.
- ✗
Car
Why it's wrong here
Even though the object is Car, the reference is Vehicle, so the field from Vehicle is used.
- ✗
Runtime error
Why it's wrong here
No runtime error occurs.
Go deeper
Related to this question
About these practice questions
One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.