• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

One class implement two interfaces with common methods??

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two interfaces have same methods.
one class implements both interfaces.
Is any problem in this? How will we distinguish the methods?
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem.

Why you need to distingush methods from these two interfaces ? Because there is no implementation in the interface so would it make any sense distingushing these two itnerfaces.
 
Hemant Agarwal
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But .NET is distinguishing why?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No idea about .NET ... does the method implementation specify which interface it is for? But in Java the logic is fairly simple.

Interface A says the implementer must have method x(). Interface B says the implementer must have method x(). If you have method x() the syntax is good and you have satisfied the compiler's checking for both interfaces.

If the documentation for interface A says x() increments the x coordinate and the doc for B says it decrements the x coordinate, the semantics are inconsistent and some client of your class will be unhappy.

So there can be cases where implementing two interfaces with matching method signatures is possible, but not correct. If .NET matches the method implementation to the interface they might get around this issue.
reply
    Bookmark Topic Watch Topic
  • New Topic