• 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:

JQ+ Question ID :957711112180

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


C:\JavaRanch>javac Test35.java
C:\JavaRanch>java Test35
Hi there
----------
The question was:
What methods have to be implemented by a class that says it implements I1 and I2 ?
The answer was:
There is no way that an method can declare an exception that satisfies both the methods.
As in my code, the class can declare no throws clause that will satisfy both interface method requirement.
Any thoughts?
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a little confused here. Maybe I am not grasping the full question. The code you have written will compile properly. I do not think that java requires that your method should throw both the exceptions if you are implementing the interfaces I1 and I2. You will be implementing the interfaces if you follow the signature -- ie the parameters. Your method will decide what your method will throw.

------------------
Hari Gangadharan
Out of the turbulance a soft voice spoke to me ...
Son smile and be happy things could be worse...
I smiled and I was happy and things became worse!
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the code will compile since there is no ambiguity.
Ambiguity will arise when you throw some exception in this case.
Similarly there would not be any compile err, when the
same variable is declared in these interfaces but not used in the sub class.. ambiguity will arise when we use the variable in the subclass.
reply
    Bookmark Topic Watch Topic
  • New Topic