When we extend two interfaces and each interface is having the same method name and type signature,so when a class extends both the interfaces,then what will happen?

Showing Answers 1 - 2 of 2 Answers

Rajesh

  • Apr 22nd, 2006
 

Hai my Name is Rajesh when we try to implement two interfaces which are having same method signature and params also within a single class then the functionality for both the functions present in those interfaces are implemented and when ir trying to access the method from class's object that is going to be invoked here it is the simple code. 

 

 

interface I1
{
void f1();
}
interface I2
{
void f1();
}
class A implements I1,I2
{
public void f1()
{
System.out.println("hai");
}
}
public class Intrs
{
public static void main(String[] S)
{
A ob=new A();
ob.f1();
}
}

output:hai

 

  Was this answer useful?  Yes

Pramod

  • Jun 21st, 2006
 

you are correct Mr. Rajesh..

this will work with methods..but when we have two data members with the same name in two different interfaces say public static final a=10; in one interface and public static final a=20;in another interface, then the class that implements both the interfaces and trying to access the veriable a.. then a runtime error(ambigueous) will be caused..

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions