I'm at a loss why the compiler error in case 4:
class TestClass2 implements I2,I1{
public void m1() throws SQLException,IOException {}
}
reads "overridden method does not throw SQLException". It does. I can declare a method to throw any number of exceptions, can't I? Each of these exceptions on their own (implementing only one of the interfaces) compile fine. Together it is always the SQLExceptions that the compiler prints as wrong.
About Question com.enthuware.ets.scjp.v6.2.607 :
Moderator: admin
-
- Posts: 27
- Joined: Mon Sep 22, 2014 1:30 pm
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.607 :
You are overriding a method that is defined in two interfaces. TestClass claims that it implements both the interfaces. So the compiler has to check if TestClass does indeed implement each of the interfaces without breaking any contract established by each individual interface. As explained here, a new checked exception breaks the contract.
Which exact exception (SQLException or IOException) the compiler thinks breaks the contract is just an implementation detail of the compiler. It could very well say that SQLException is OK but IOException is not. Try changing the order of your implements clause and see if the message changes.
HTH,
Paul.
Which exact exception (SQLException or IOException) the compiler thinks breaks the contract is just an implementation detail of the compiler. It could very well say that SQLException is OK but IOException is not. Try changing the order of your implements clause and see if the message changes.
HTH,
Paul.
-
- Posts: 27
- Joined: Mon Sep 22, 2014 1:30 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.607 :
Thanks for the clarification.
Who is online
Users browsing this forum: No registered users and 8 guests