• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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: 76842
366
  • 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
 
Space pants. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic