• 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

A class implements a method from two interfaces?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

In the code...



Can I assume that the class doesn't care how many times a method signature is duplicated in multiple interfaces?
The class just has to make sure that it implements the method regardless of how many times the method signature is listed in different interfaces?

Likewise does the same apply when a subclass extends a parent class that has a method that is also mentioned in an interface...



In fact, does MyClass2 have to have an implementation of the doSomething(); method at all, as a doSomething(); method is inherited from MyClass1?

Thanks for your help.
 
Jack McGuire
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've tried coding up little examples and things would appear to work as I expected.
In the 2nd piece of code, you don't have to implement a method signature mentioned in an interface, if the method has been implemented by the parent class.

Is that it? Or is there anything more to be aware of?
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you've got it right. Of course, the point where you need to be careful is where there are two identical methods which are intended to have different meaning! At that point you need to change your design - though I don't think I've ever actually hit that problem in real code.
 
Jack McGuire
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cheers Matthew!
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote: . . . I don't think I've ever actually hit that problem in real code.

That means you have only used interfaces from people who know what they are doing and give their methods names which accurately describe what they do
 
reply
    Bookmark Topic Watch Topic
  • New Topic