3

Below code,

interface I3{
    boolean abc();
}; 
interface I2{
    void abc();
};
public class Example1  implements I3, I2{
    @Override
    public void abc() {
        //Eclipse IDE picked this unimplemented method with the compiler error

    }
}

Is it the responsibility of a programmer to not get into this situation?

Why Java has allowed an interface extending multiple interfaces? when java has already avoided similar problem of a class inheriting multiple super classes?

In case of similar constants inherited from multiple interfaces, interfacename.constantname in a subclass avoids ambiguity.

overexchange
  • 15,768
  • 30
  • 152
  • 347
  • The best thing to do is try to compile it for yourself and find out. It will throw an error saying `the return type is incompatible with I3.abc()` – Codebender Jul 26 '15 at 14:46
  • The two methods have conflicting `return` types, then it will be a compilation error. This is the general rule of `inheritance`, `method overriding`. – SatyaTNV Jul 26 '15 at 14:49
  • @Satya Definition of override is, *If the method not inherited is not abstract, then the new declaration is said to override it*. In this case, method `abc` is abstract. – overexchange Jul 26 '15 at 14:53
  • @overexchange see this http://stackoverflow.com/questions/2801878/implementing-two-interfaces-in-a-class-with-same-method-which-interface-method – SatyaTNV Jul 26 '15 at 14:59

2 Answers2

0

Yes it is definely the responsability of the programmer to not get into this situation.

Interface is a way to have multiple inheitence, we must not confuse the JVM with these kind of conflicts.

Anthony Raymond
  • 7,434
  • 6
  • 42
  • 59
-1

because both abc()method have the same signature (return type is not a part of method signature) and java can't make difference between theme and this situation cause a conflict

hamid_c
  • 849
  • 3
  • 11
  • 29