1Z0-811 Object-Oriented Programming Practice Question
Exhibit
class Animal {
public void sound() {
System.out.println("Animal sound");
}
}
class Dog extends Animal {
public void sound() {
System.out.println("Bark");
}
public void fetch() {
System.out.println("Fetching");
}
}
public class Test {
public static void main(String[] args) {
Animal a = new Dog();
a.sound();
((Dog) a).fetch();
}
}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
✓
Bark\nFetching
The object is a Dog, so sound() prints 'Bark'. The cast to Dog is valid (the object is actually a Dog), so fetch() prints 'Fetching'. Options A, B, D are incorrect because no ClassCastException occurs; the Dog class overrides sound() and has fetch() method.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Bark\n (then throws ClassCastException)
Why it's wrong here
C is wrong: the cast is valid because a refers to a Dog object.
- ✗
Animal sound\n (then throws ClassCastException)
Why it's wrong here
D is wrong: sound() is overridden and no exception occurs.
- ✓
Bark\nFetching
Why this is correct
B is correct: polymorphism calls Dog's sound() and cast allows fetch().
- ✗
Animal sound\nFetching
Why it's wrong here
A is wrong because sound() is overridden and the actual object is Dog.
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 →
Same concept, more angles
1 more way this is tested on 1Z0-811
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Refer to the exhibit. What is the output?
hard- A.Runtime error
- B.No output
- C.Compilation error
- ✓ D.Photo
- E.Document
Why D: The object is Photo, and print() is overridden, so dynamic binding calls Photo's print method.
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.