Oracle
1Z0-803 · Question #260
Given: interface Pet { } class Dog implements Pet { } public class Beagle extends Dog{ } Which three are valid?
The correct answer is A. Pet a = new Dog(); D. Dog d = new Beagle(); E. Pet e = new Beagle();. Not B, not C: Pet is abstact, cannot be instantiated. Not F: incompatible type. Required Beagle, found Dog.
Working with Inheritance
Question
Given:
interface Pet { } class Dog implements Pet { } public class Beagle extends Dog{ } Which three are valid?
Options
- APet a = new Dog();
- BPet b = new Pet();
- CDog f = new Pet();
- DDog d = new Beagle();
- EPet e = new Beagle();
- FBeagle c = new Dog();
How the community answered
(34 responses)- A76% (26)
- B12% (4)
- C9% (3)
- F3% (1)
Explanation
Not B, not C: Pet is abstact, cannot be instantiated. Not F: incompatible type. Required Beagle, found Dog.
Topics
#polymorphism#inheritance#interfaces#type compatibility
Community Discussion
No community discussion yet for this question.