1

I have below 2 interfaces.

public interface I1 {
    
    public void show();

}

Another one

public interface I2 {
    
    public void show();

}

We have a class which is implementing both.

public class Main implements I1,I2 {

@Override
public void show() {
    
    System.out.println("Hello I am mahima");
}

I ran the program , there is no compilation or run time error. How can I find which interface method is getting called here? Is there anyway to find it?

This question was asked in an Amazon interview first round.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Shruti sharma
  • 199
  • 6
  • 21
  • 67

1 Answers1

7

Mu. That one method is the implementation for both interfaces. That show you wrote cannot be said to be 'I1's show' vs. 'I2's show'. It's both:

I1 i = new Main();
i.show(); // works, prints mahima
I2 j = new Main();
j.show(); // works, prints mahima
rzwitserloot
  • 85,357
  • 5
  • 51
  • 72