On the assessment test on page xxxi for the question #3 the correct answers are including the option D as well which says that the code will not compile due to the line 5.
I ran the code with the javac, and also in intellij and eclipse as well and there was no error signalled on line 5. What exactly is the issue with the line 5 ? Why is the declaration of Cougar ( edited here - initially i said Puma ) invalid ?
Thanks for the reply. I noticed that there is an explanation in the online errata but even so , I find it confusing that there is no statement for D if it's correct or not in the online errata. Shouldn't that be updated to state that D is not a correct answer? Even if the declaration of Cougar is invalid, that does not triggers a compiler error on line 5 that would make D a valid answer.
In the online errata, this is what it's said :
#3 – 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”.
I would change it to state that :
D is not a correct answer due to the fact that there is no compiler error on line 5. However, in the explanation, “Puma is invalid” should be “Cougar is invalid” for the explanation for D.
Liviu Jianu wrote:I ran the code with the javac, and also in intellij and eclipse as well and there was no error signalled on line 5.
Are you sure about Eclipse? Because I just created this code snippet in Eclipse and I get the following compiler error on line5:I have also attached a screenshot of the Cougar.java source file with an overview of all compiler errors (given by Eclipse).
Jeanne Boyarsky wrote:I didn't get the compiler error at the command line. (Eclipse and the command line don't always agree on errors)
Yeah, I know that different compilers provide sometimes different compiler errors. Because OP mentioned that javac, IntelliJ, and Eclipse didn't signal the error on line5, I just tried it in Eclipse (out of curiosity) to see which compiler errors you get.
And at work we are using IntelliJ, so I did the same test with this IDE and although IntelliJ only marks 2 compiler errors in the code (with a red line), it gives you all 3 compiler errors as well in the Problems view. Attaching a screenshot of the Cougar.java source file with an overview of all compiler errors (given by IntelliJ).