0

When we implement multiple iheritance for the class RunExample it is running fine without any issues or errors at compile time or runtime. How does jvm knows which method to implement when same methods are declared in different interfaces?

package InterfaceSegregation;

public interface A {

    public void work();
    public void takeBreak();
}



package InterfaceSegregation;

public interface B {
    public void takeBreak();
}




package InterfaceSegregation;

public class RunExample implements A,B{
    public static void main(String[] args){
        RunExample e = new RunExample();
        System.out.println(e instanceof A);
        System.out.println(e instanceof B);

    }

    @Override
    public void work() {
        // TODO Auto-generated method stub

    }

    @Override
    public void takeBreak() {

    }
}
  • 2
    Possible duplicate of [Java - Method name collision in interface implementation](https://stackoverflow.com/questions/2598009/java-method-name-collision-in-interface-implementation) – azro Oct 12 '19 at 14:53
  • 2
    What's to confuse? A concrete class can only implement an abstract method once, no matter how many of its super-interfaces or super-(abstract)-classes declare it. – Kevin Anderson Oct 12 '19 at 15:01

1 Answers1

-1

Basically implementing an interface is a means of controlling what methods will the object have.
As long as the signature including return type is the same java will allow it.

Check the Oracle docs.