1Z0-803 · Question #158
Given: What is the result?
The correct answer is D. Y Y Y. The program demonstrates method overriding where the subclass's overridden method is consistently invoked due to polymorphism, leading to the repeated output of the subclass's specific value.
Question
Given:
What is the result?
Exhibit
Options
- AX X X
- BX Y X
- CY Y X
- DY Y Y
How the community answered
(34 responses)- A3% (1)
- B6% (2)
- C9% (3)
- D82% (28)
Why each option
The program demonstrates method overriding where the subclass's overridden method is consistently invoked due to polymorphism, leading to the repeated output of the subclass's specific value.
This would occur if the superclass's implementation or value ('X') was always accessed, indicating no overriding or incorrect polymorphic dispatch.
This output suggests a mix of superclass and subclass values, which is unlikely for repeated access to a consistently overridden or shadowed member under the same conditions.
This output also suggests a mixed result that doesn't align with a straightforward polymorphic invocation where the subclass's behavior predominates once established.
This result typically occurs in a scenario where a superclass has a member (e.g., a method or a field accessed via an overridden method) with value 'X', and a subclass overrides that member with value 'Y'. When an instance of the subclass is created and its methods are invoked (possibly three times, or a loop printing three times), the overridden method (or accessor for the shadowed field) from the subclass is called, consistently returning 'Y'.
Concept tested: Polymorphism and method overriding
Source: https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html
Topics
Community Discussion
No community discussion yet for this question.
