GeeCON Prague 2014*
The moose likes Mock Exam Errata and the fly likes overriding a method... non checked exceptions? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "overriding a method... non checked exceptions?" Watch "overriding a method... non checked exceptions?" New topic
Author

overriding a method... non checked exceptions?

Paulo Silveira
Ranch Hand

Joined: May 21, 2002
Posts: 32
from this mock:
http://valiveru.tripod.com/java/jvaltest.html


It says that the only right answers are C and D, but B also compiles, right? It is never a problem to add a RuntimeException to the method throws clause.
For example, I have the Daddy class, which has the methodX() that throws nothing.
And class Son extends Daddy, which throws RuntimeException, this compiles fine!!!
i really think that the ansswer of this question ios wrong, and you?
[ adjusted spacing in code block ]
[ May 26, 2002: Message edited by: Jessica Sant ]
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
I think you're right. It's never required to specify any non-checked exceptions in your throws clause, but specifying them is certainly allowed.
I'd say B is a correct answer as well.
(Note however, in a real program you usually won't specify any non-checked exceptions because that will just clutter up your code and doesn't add a lot of value.)
[ May 26, 2002: Message edited by: Rob Ross ]

Rob
SCJP 1.4
Paulo Silveira
Ranch Hand

Joined: May 21, 2002
Posts: 32
thanks a lot for your kind and fast answer
Steven Sun
Greenhorn

Joined: Apr 29, 2002
Posts: 26
A non-checked Exception is not required to be thrown,I think sun provide this is to let the programmer to deal with the Runtime Exception in catch clause,and also not deal with it at all,it is up to you.


newly SCJP2 <img src="tongue.gif" border="0">
Karen Leoh
Ranch Hand

Joined: Dec 03, 2001
Posts: 40
Hi
Just to clarify again. Thus, the correct answer for the question is B,C, D, and E.
B and E are correct because specifying non-checked exceptions in your throws clause is allowed although not required.
Correct me if I'm wrong. Thanks a lot.


--------------------<p>Karen Leoh<br />Sun Certified Programmer for Java™ 2 Platform
Swati Gupta
Ranch Hand

Joined: May 28, 2002
Posts: 106
E option is not correct as it does not specify the checked exception(Base or its superclass Exception) in the throws clause.
Steve Chernyak
Ranch Hand

Joined: Oct 19, 2000
Posts: 113
In "Effective Java" Joshua Bloch says that you should specify only checked exceptions in the methods throws clause, and that you should specify the unchecked exceptions in the javadoc documentation for the method.
Both are legal, but this is better style.
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

moving this to mock exam errata now that its been determined the answer is incorrect. Please continue the dicsussion there.
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
So what is the conclusion? Is E is correct or not? I don't think E is correct.


Thanks,<br />Thiru<br />[SCJP,SCWCD,SCBCD]
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

E is not correct -- although it declares that it throws the Unchecked exception (RuntimeException) -- it doesn't declare that it throws the checked exception (Base/SubException). And hence would through a compile time error.
 
GeeCON Prague 2014
 
subject: overriding a method... non checked exceptions?