• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff


Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic