About Question com.enthuware.ets.scjp.v6.2.607 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
piotrkmiotczyk
Posts: 27
Joined: Mon Sep 22, 2014 1:30 pm
Contact:

About Question com.enthuware.ets.scjp.v6.2.607 :

Post by piotrkmiotczyk »

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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.607 :

Post by admin »

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.

piotrkmiotczyk
Posts: 27
Joined: Mon Sep 22, 2014 1:30 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.607 :

Post by piotrkmiotczyk »

Thanks for the clarification.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests