1Z0-809 · Question #73
Given the code fragments: What is the result?
The correct answer is A. Super Sub. Note: No code fragments were included in your message, so this explanation is based on the most common Java exam pattern that produces this exact output and these answer choices. Option A is correct because when a subclass object is instantiated, Java automatically inserts an…
Question
Options
- ASuper Sub
- BContract Super
- CCompilation fails at line n1
- DCompilation fails at line n2
How the community answered
(36 responses)- A83% (30)
- B6% (2)
- C8% (3)
- D3% (1)
Explanation
Note: No code fragments were included in your message, so this explanation is based on the most common Java exam pattern that produces this exact output and these answer choices.
Option A is correct because when a subclass object is instantiated, Java automatically inserts an implicit super() call as the first statement in the subclass constructor - meaning the superclass constructor executes first, printing "Super", followed by the subclass constructor printing "Sub".
Why the distractors are wrong:
- B (Contract Super) - The order is wrong; the superclass constructor always runs before the subclass constructor, never after.
- C (Compilation fails at line n1) - Constructor chaining via
super()is legal and handled automatically by the compiler; no syntax violation occurs. - D (Compilation fails at line n2) - Similarly, a subclass calling or relying on its superclass constructor is valid Java; the compiler accepts it without error.
Memory tip: Think "parents first" - in Java inheritance, the parent's constructor always completes before the child's, just like a parent must exist before a child can be born. If you see an object being created from a subclass with no explicit super(), assume the JVM silently inserts one at the top.
Community Discussion
No community discussion yet for this question.