Question from Enthuware
Consider these two interfaces:
interface I1
{
void m1() throws IOException;
}
interface I2
{
void m1() throws SQLException;
}
What methods have to be implemented by a class that says it implements I1 and I2 ?
I selected
public void m1() throws Exception
which is wrong
Is this because m1() is throwing a broader Exception?
Then please explain why the class that implements interface I1 and I2 can throw Exception. Please see Enthuware's explanation below:
When interfaces are involved, more than one method declaration may be implemented by a single method declaration. In this case, the overriding declaration must have a throws clause that is compatible with ALL the overridden declarations. The declaration public void m1(){} satisfies both the declarations. Example...