1Z0-803 · Question #31
Given: What should statement1, statement2, and statement3, be respectively, in order to produce the result? Shape: constructor Square: foo Shape: foo
The correct answer is D. Option D. To produce the specified output, statement1 creates a Square object, which implicitly calls the Shape constructor. Statement2 then invokes a Square-specific method that prints "Square: foo", and statement3 calls the inherited foo method from the Shape class on the same Square obj
Question
Given:
What should statement1, statement2, and statement3, be respectively, in order to produce the result? Shape: constructor Square: foo Shape: foo
Exhibits
Options
- AOption A
- BOption B
- COption C
- DOption D
How the community answered
(58 responses)- A26% (15)
- B5% (3)
- C12% (7)
- D57% (33)
Why each option
To produce the specified output, statement1 creates a Square object, which implicitly calls the Shape constructor. Statement2 then invokes a Square-specific method that prints "Square: foo", and statement3 calls the inherited foo method from the Shape class on the same Square object.
This option would not produce the specified sequence, likely by calling Shape's foo method incorrectly, or failing to call Square's specific method.
This option probably alters the order of calls or calls methods that print different strings, thus failing to match the target output.
This option likely makes incorrect method calls or omits necessary object instantiations, preventing the output Shape: constructor Square: foo Shape: foo from being generated.
Option D contains the necessary statements to first instantiate a Square object (triggering Shape's constructor), then invoke a method unique to the Square class to print "Square: foo", and finally call the inherited foo method from the Shape class on the Square object, resulting in "Shape: foo". This sequence exactly matches the desired output.
Concept tested: Object-oriented inheritance, constructor invocation, method polymorphism
Source: https://docs.oracle.com/javase/tutorial/java/javaOO/inheritance.html
Topics
Community Discussion
No community discussion yet for this question.

