Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface

 
subash chandar
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a simple program that implements two interface that
contains same abstract methods.Does any one know which method will be overrided in the implemented class and why.

Here is my program

interface a {
void display();
}
interface b {
void display();
}

class test implements a,b {
......
public void display() { }
.......
}
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you implement an interface you promise to provide the methods specified in the interface. The interface makes you do that much but the interface can't specify what you should do. So you'll make your method display() do whatever is right for you, and anybody who calls display() will have to live with the results.

Say you create a class that implements InterfaceA and InterfaceB. You could pass a single object instance to either of these methods and your object would do exactly the same thing both times.

So to your question "which does it override" the answer is none. It implements rather than overrides, and one implementation is good enough for both interfaces.

Hope that helps!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic