• Post Reply Bookmark Topic Watch Topic
  • New Topic

A class implements a method from two interfaces?  RSS feed

 
Jack McGuire
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Cheers Matthew!
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!