1Z0-803 · Question #193
Given the code fragments: What is the result?
The correct answer is A. Super. This question tests understanding of method invocation in Java inheritance, specifically when a superclass's method implementation is executed.
Question
Given the code fragments:
What is the result?
Exhibit
Options
- ASuper
- BContract
- CCompilation fails at line n1
- DCompilation fails at line n2
How the community answered
(29 responses)- A55% (16)
- B7% (2)
- C14% (4)
- D24% (7)
Why each option
This question tests understanding of method invocation in Java inheritance, specifically when a superclass's method implementation is executed.
The code fragment likely involves an instance where either a superclass method is called directly, or a subclass's overridden method explicitly invokes `super.methodName()` to execute the parent class's implementation, resulting in 'Super' being printed.
This output would only occur if a subclass's overridden method that prints 'Contract' was invoked and did not then call its superclass's method, or if there was a separate method printing 'Contract' that was executed.
There is no inherent syntax error or logical flaw suggested by the output 'Super' that would cause a compilation failure at a specific line 'n1'.
There is no inherent syntax error or logical flaw suggested by the output 'Super' that would cause a compilation failure at a specific line 'n2'.
Concept tested: Java inheritance method invocation and `super`
Source: https://docs.oracle.com/javase/tutorial/java/IandI/super.html
Topics
Community Discussion
No community discussion yet for this question.
