This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriding and Exceptions - Examlab question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding and Exceptions - Examlab question" Watch "Overriding and Exceptions - Examlab question" New topic
Author

Overriding and Exceptions - Examlab question

Larry Olson
Ranch Hand

Joined: Feb 03, 2009
Posts: 142
Hi,

Time for me to ask a question

Here is a question from Examlab Test # 3



My question:

Even though class UDI's buildNow() method doesn't explicitly declare that it throws IOException, is it implicit that it throws an IOException, since UDI implements Buildable and Buildable's buildNow() method declares to throw an IOException ?

I do understand the rules about overriding and exceptions i.e. The overriding method can't throw more or broader exceptions than the overridden method. But the question is if the overriding method doesn't declare to throw any exceptions at all, does it still implicitly throw all the exceptions that is declared in the overridden method?

Thanks.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

But the question is if the overriding method doesn't declare to throw any exceptions at all, does it still implicitly throw all the exceptions that is declared in the overridden method?

No, since the buildNow method in UDI doesn't explicitly declare IOException, so it cannot throw that exception, there is no implicit inheritance of thrown exceptions...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Larry Olson
Ranch Hand

Joined: Feb 03, 2009
Posts: 142
there is no implicit inheritance of thrown exceptions...


Thanks. You put it very clearly. I have been confused about this all along.
 
jQuery in Action, 2nd edition
 
subject: Overriding and Exceptions - Examlab question
 
Similar Threads
exception
Overriding problem
Exceptions in Overriding methods??
Overriding and Exceptions
Exam Lab Question