Email address:
Password:
SCJP/OCPJP 1.6 certification
Practice Exams and Training
SCJP Online Training » Discussions

Checked Exception while implementing the Interface's method

Hi,


Normally, the method declared in an interface is implemented in the first concrete class of the one which is implementing this interface. In this case, the first concrete class implementing the Interface's methods is the Nonc class which should also consider the IOException since this is a checkedexception.


How can this be considered without taking into the IOException taken into consideration

There is no such requirement as the subclass method needs to have in the throws clause the checked exceptions the super class method has. It's the other way around - if you add a checked exception to a method in a subclass, all super classes must have a proper throws clause to support it.


In this particular question, the super class buildNow method has IOException in its throws clause. That doesn't mean you should also have it in the sub class method. On the other hand, if the subclass method had IOException in its throws clause, the super class method would need to have IOException or a super type of it in its own throws clause.


To see why, and for an easy way to figure out the restrictions of exceptions in throws clause like this, please watch our exceptions video: http://www.examlab.org/v/exceptions


ExamLab © 2008 - 2024