What is the final answer to Question 3 in Assessment Test? page (xxxi)
C and D OR C,D and E
I apologize for not explaining well
C, D, E. First, the method getTailLength() in the interface HasTail is assumed to be
public, since it is part of an interface. The implementation of the method on line 3 is
therefore an invalid override, as protected is a more restrictive access modifier than
public, so option C is correct. Next, the class Cougar implements an overloaded version
of getTailLength(), but since the declaration in the parent class Puma is invalid,
it needs to implement a public version of the method. Since it does not, the declaration
of Puma is invalid, so option D is correct. Option E is incorrect(Here I'm confused), since Puma is marked
abstract and cannot be instantiated. The overloaded method on line 11 is declared
correctly, so option F is not correct. Finally, as the code has multiple compiler errors,
options A, B, and G can be eliminated. For more information, see Chapter 5.
Q3. What is the output of the following code? (Choose all that apply)
C. The code will not compile because of line 3.
D. The code will not compile because of line 5.
E. The code will not compile because of line 7.
F. The code will not compile because of line 11.
G. The output cannot be determined from the code provided.
In Point number 3:
'Puma is invalid' should be 'Cougar is invalid' for the explanation for D
'E is incorrect' should be 'E is correct'
I'm not sure how official this list is though; Jeanne, Scott, can you confirm that this is indeed an error in the book?
The answer is correct. In the explanation, “Puma is invalid” should be “Cougar is invalid” for the explanation for D. And “E is incorrect” should be “E is correct”. In the second printing, we introduced a regression error. It should be “since the declaration in the parent class Puma is invalid” and then “the declaration of Puma is invalid”
Thank you all and best regards