Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding and Exceptions - Examlab question

 
Larry Olson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Larry Olson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is no implicit inheritance of thrown exceptions...


Thanks. You put it very clearly. I have been confused about this all along.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic