Naming Conflicts Inside Interface

Case#1:If two interfaces have the two are more same methods, **and then** only one method implementation is enough from both interfaces.

`interface Left { public void m1(); }

interface Right{public void m1();}

class Central implement Left, Right
{
public static void main(String arg[])

{
public void m1(){ }
}
}`

Case#2:The interface having same method name but different arguments. `Interface Inter

{

public void m1();

public void m1(int x);

}`

Case#3:Same method name, same arguments but different written types. `Interface Left{public void m1();}

Interface Right{public int m1();}

class Central implement Left, Right

{

public static void main(String arg[])

{

public void m1() {}// error

public int m1(){}// error

}

}
`
In the above class same method signature m1 is not allow .violation leads to compile time error.

Exceptional case: We can’t provide implementation at a time for two or more interfaces having methods with same signature but different return **type.**

Variable Naming conflicts: `interface Left{int x=10;}

interface Right{int x=100;}

class Central implement Left, Right

{
public static void Main(String arg[])

{

System.out.println(x); // reference to x is ambiguous both variables
System.out.println(Right.x);

System.out.println(Left.x);

}

}`

we can resolve variable naming conflicts using interface name.(i.e instead of x we have to specify left.x or right.x).

  • One of my friend wanted the answers so posted this content