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.

4
  • 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() Commented Jul 26, 2015 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. Commented Jul 26, 2015 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. Commented Jul 26, 2015 at 14:53
  • @overexchange see this stackoverflow.com/questions/2801878/… Commented Jul 26, 2015 at 14:59

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Can you tell why you are downvoting the answer? did i said a mistake?
-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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.