• 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

Multiplae Interface with commaon method

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


Above code complies fine.But is there a way to find which add() is being implemented in class.

and if i change it this way




this also compiles fine without any error.

Is there a way to distinguish the method of class from interface method while using in class
As some other languages supports it like vb.
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here both intefaces have a method with same name, and your class implementing that method in it. it is the implementation of your class for that method.
i think it can be treated as method of both interface.


 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Bobal wrote:Is there a way to distinguish the method of class from interface method while using in class
As some other languages supports it like vb.


Short answer: no. If a class inherits the same method from multiple interfaces (or from a class and an interface), then the single implementation of that method applies to all those interfaces.
 
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The basic and important reason for not being able to distinguish is to avoid Diamond problem in Java which causes confusion as to which method is inherited from two different subtypes.

This is also the reason interfaces were brought in Java and the abstract methods which don't have any body and hence no confusion as to which method is being inherited and overridden.
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic