• Post Reply Bookmark Topic Watch Topic
  • New Topic

Throw Exception in Overriden Method  RSS feed

 
Utha Ramadhan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
need help here..

i am practicing for OCPJP exam, and i found an explanation that a little bit confusing on Ganesh book..
it is the question..



Which one of the following options correctly describes the behavior of this program?


and the answer is (definitely) --> The program will print : InvalidKeyException exception, but when i saw the explanation, it tells

It is not necessary to provide an Exception thrown by a method when the method is overriding a method defined
with an exception (using the throws clause).


i dont know, but i think it will compiled because the Exception that is thrown by the foo method in DeriDeri class is inherited from unchecked exception.. so it is not necessary to declare throws statement on its method.. and if the exception was checked exception the answer must be different right?
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are correct. Where did you get that quote? Was it from the book you quoted? Did you copy it exactly? Because it is quite confusing to read.
I suggest you remind yourself of the Exceptions part of the Java® Tutorials, which would be helpful.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume you have verified your answer by running that code?
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And where does
import java.lang.*;
come from?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!