• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

From JQPlus : QuestionID 957711112180

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question ID : 957711112180
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 ?
OPTIONS :
1. Both, public void m1() throws SQLException, and public void m1() throws IOException
2. public void m1() throws IOException
3. The class cannot implement both the interfaces as they have conflicting methods
4. public void m1() throws SQLException, IOException
5.None of the above
Correct answer : 5.
The explanation mentions, "that the overiding method must have a throws clause
that is compatible with ALL the overridden declarations .So public void m1() satifies both the declarations"
But i fail to understand the meaning !
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can not declare that you throw an exception that isn't in the interface. If you decalre that you throw SQLException, that isn't in I1. If you decalre that you throw IOException, that isn't in I2. Therefore you must not declare that you throw any exceptions. Programmatically, that will mean that any exceptions generated in your code will have to be handled.
------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A rather very basic doubt,
Can we throw more that one exception in a throws clause..?
public void m1() throws IOException,Exception
thanx
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swati,
You can throw more than one exception in the throws clause of the method, just check wether the method is overriding any method, if yes you can not throw any checked exception not thrown in overriden method.
--Farooq
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic