• 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

Multiple inheritence with interface

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



In preceding code how to provide implementation of add() in Test class
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

raj chiru wrote:
In preceding code how to provide implementation of add() in Test class



implementation is nothing but writting the logic(coding) for a method

example

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
simple, you can't so, you don't. That isn't an issue when following the javabean convention...

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a collision. Collisions between interface methods can always be resolved providing the following three conditions apply:
  • 1: The methods have the same signature. (Otherwise it is overloading and not a collision at all).
  • 2: The methods have compatible intent (see below).
  • 3: The methods have the same return type. (You will have to check in the Java Language Specification for the exact details.)
  • You are violating no 3 here, and it will never compile.
    This is overloadingAnd this is incompatible intentObviously the WackyArithmetic#add method is only suitable for jokes, but I challenge you to implement both those interfaces in accordance with their specifications given.

    Have a look at these three add methods: note that the first is intentionally given a vague specification so both sub-interfaces can implement it differently, but still be compatible in intent. 1 2 3
     
    Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic