Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

interface

 
Greenhorn
Posts: 8
  • 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() { }
.......
}
 
(instanceof Sidekick)
Posts: 8791
  • 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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!