aspose file tools*
The moose likes Beginning Java and the fly likes interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "interface" Watch "interface" New topic
Author

interface

subash chandar
Greenhorn

Joined: Feb 07, 2005
Posts: 8
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

Joined: Jan 29, 2003
Posts: 8791
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!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: interface