Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Assessment Test Question #3 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Greenhorn
Posts: 6
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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 ?



Thank you!
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see compile time error in the code

You cant create an object out of Puma as it is an abstract class.

Hope the above line clarifies your doubt.
 
Revathy Balajee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also all interface methods by default public so your Puma class cant change the method to protected.
 
author & internet detective
Posts: 39890
798
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liviu,
You are correct. This is an error in the book. D is not a correct answer. There is a thread discussing this. It's also listed in the book's errata.
 
Liviu Jianu
Greenhorn
Posts: 6
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Liviu,
You are correct. This is an error in the book. D is not a correct answer. There is a thread discussing this. It's also listed in the book's errata.



Hello @Jeanne,

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.



What do you think ?

Thanks!
 
Jeanne Boyarsky
author & internet detective
Posts: 39890
798
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah. That's a different errata. In the case of #3, it isn't clear. (compilers vary.) I'll not it could be clearer.
 
Liviu Jianu
Greenhorn
Posts: 6
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Ah. That's a different errata. In the case of #3, it isn't clear. (compilers vary.) I'll not it could be clearer.



I understand that D is still not a correct answer but you are saying that with different JDK compiler versions, there could be a compile error there on line 5?

What is your suggestion for the errata in this case ?

Thank you very much!
 
Jeanne Boyarsky
author & internet detective
Posts: 39890
798
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The errata is "we should re-write the question to be clearer". Probably by not making line 5 a choice at all.
 
Liviu Jianu
Greenhorn
Posts: 6
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:The errata is "we should re-write the question to be clearer". Probably by not making line 5 a choice at all.



Understood. Thanks!
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Liviu Jianu,

First of all, a warm welcome to CodeRanch!

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).

Hope it helps!
Kind regards,
Roel
cougar-compiler-errors-eclipse.jpg
[Thumbnail for cougar-compiler-errors-eclipse.jpg]
 
Jeanne Boyarsky
author & internet detective
Posts: 39890
798
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel,
I didn't get the compiler error at the command line. (Eclipse and the command line don't always agree on errors)
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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).
cougar-compiler-errors-intellij.jpg
[Thumbnail for cougar-compiler-errors-intellij.jpg]
 
A wop bop a lu bop a womp bam boom! Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!