• Post Reply Bookmark Topic Watch Topic
  • New Topic

Query on Interface,one question confused me  RSS feed

 
Ranch Hand
Posts: 1078
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one Query on Interface,in which one question confused me.Sentence is as below.

'Interfaces can be implemented by any class, from any inheritence tree.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is that quote from?
It is not quite true. You can writeanywhere … provided Foo does not already have a method whose intent clashes with a method in Bar. That means, same signature, same return type, different meaning.That is obviously a really daft example, but when you have the method in Foo, will it return 2 × i or -i?
 
Vishal Hegde
Ranch Hand
Posts: 1078
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is from SCJP6 book.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I hope my answer was helpful.
 
Vishal Hegde
Ranch Hand
Posts: 1078
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Where is that quote from?
It is not quite true. You can writeanywhere … provided Foo does not already have a method whose intent clashes with a method in Bar. That means, same signature, same return type, different meaning.That is obviously a really daft example, but when you have the method in Foo, will it return 2 × i or -i?



Just curious, which method will be called will it be from a class or Interface.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whichever method is implemented in the class, following the normal rules of overriding and polymorphism. As you already know, you can't have two override‑equivalent methods in the same class.

Asking whether you have the interface method or the class method doesn't mean anything. The correct answer is both. You get the method from the interface and the class provides the implkementation. So both become the same method.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!