Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about exception questions 17 and 18 (Java OCA 8 Programmer I Study Guide, Sybex)

 
henry leu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using the Oracle Certified Associate Java SE 8 Programmer I by Jeanne Boyarsky and Scott Selikoff. I am confused at the answers they provide to the questions on page 331, questions 17 and 18.

See attached pictures for the questions and answers. I think the answers are incorrect.

Problem #17: the answers are A, C, D, E. But why not B also? The roar() method's exception HasSoreThroatException extends Exception. I think B works too. No?

Problem #18: the answers are A, B, C, E. But I think A is incorrect. I think check exceptions MUST be handled and declared. Not ALLOWED.



[edit] removed images
 
Murat Kutluer
Greenhorn
Posts: 21
IntelliJ IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry,

Q17: B is wrong because it declared broader exception. This is from chapter 4:

The method in the child class may not throw a checked exception that is new or broader than the class of any exception thrown in the parent class method.

Q18: Yes it is arguable. You may interpret that if something is required, it is olsa allowed.

Murat
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi henry leu,

First of all, a warm welcome to CodeRanch!

henry leu wrote:Problem #17: the answers are A, C, D, E. But why not B also? The roar() method's exception HasSoreThroatException extends Exception. I think B works too. No?

No, you are incorrect! Answer B will result in a compiler error. Do you want to know why? Just read this topic. It gives a detailed explanation about the exact same question (and provides a link to another topic with an even more detailed explanation with a bunch of other code snippets. Definitely worth reading!

henry leu wrote:Problem #18: the answers are A, B, C, E. But I think A is incorrect. I think check exceptions MUST be handled and declared. Not ALLOWED.

That seems to be an English thing. So it is not a typo. We had a fairly lengthy discussion on the topic though. Here is another topic about this question (with exactly the same conclusion).

Hope it helps!
Kind regards,
Roel

PS. I have removed the images from your first post because images are not searchable and thus are pretty useless as they are not indexed by the forum's search engine. Therefore their use is discouraged for posting mock questions, code snippets and/or answer options. Hope that's ok with you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic