Of the three, only option II will correctly implement code for the constructor of the Hen class. First, the Bird class is the superclass of Hen; thus, a Hen object must inherit the parameters of a Bird object. To do this, one must use the statement “super()” as the first statement in the Hen constructor. This immediately eliminates option III, which lacks the super() statement. Next, the super() statement looks in the Bird class for a constructor that takes the parameters listed within its parenthesis. Option I simply states “super();”, so Java™ will look in the Bird class for a no-args constructor. However, Bird doesn’t contain a no-args constructor, so option I is eliminated. On the other hand, option II states “super(species);”, so Java™ will look in the Bird class for a constructor containing the parameter species. The constructor Bird contains this; thus, only option II correctly implements code for the constructor of the Hen class.
−Phoenix
PS: Line 9 of the Owl code mistakenly says “Systme” instead of “System”.
PPS: Line 8 of the Hen code is missing a “"”.
Your explanation is concise and technically accurate, a well deserved 100 XPs awarded for this completion.
ReplyDelete