0

I have a very basic question

Suppose we have two Interfaces i.e. I1, I2 and class C implementing both Interfaces

public interface I1 
{
    public void m1();

}
public interface I2 
{
    public int m1();

}

public class C implements I1,I2
{

}

Here how to resolve ambiguity issues?? Two methods with the same name having different return types

  • @luk2302 no, that is not related – Stultuske Jul 15 '21 at 07:18
  • @Rajat use meaningful names, and you won't have this. – Stultuske Jul 15 '21 at 07:19
  • 1
    @Stultuske it is a perfect duplicate, the top answer answers the entire question perfectly, with examples that work and that do not work and explain why. – luk2302 Jul 15 '21 at 07:24
  • @Stultuske *"If a type implements two interfaces, and each interface define a method that has identical signature, then in effect there is only one method, and they are not distinguishable. If, say, the two methods have conflicting return types, then it will be a compilation error. This is the general rule [...] and applies also to possible conflicts not only between 2 inherited interface methods, but also an interface and a super class method, or even just conflicts due to type erasure of generics."* – luk2302 Jul 15 '21 at 07:24
  • Solution: either make the method names different,make the number of arguments different or make the types of the arguments different. – Stephen C Jul 15 '21 at 07:48

0 Answers0