Interviews5 answers
The implemented method would be of which interface ? There are two interfaces B and C each having the same method public m1() class A implements B and C. If class A has to implement method m1, the implemented method would be of which interface ?
Posted Nov 15, 2015, 6:07 AM EST.NET
5 Answers
If you give Simply give m1() implementation then it is show compile time error due to conflict . you must give implemetation as B.m1() or C.m1() then it will target B or C interface respectively.
Ravibhushan KumarPosted Oct 19, 2021, 9:51 AM EDT
When class A will implement method m1, it will be implementing both interfaces. When we create object of A with reference of interface B, then it will be implementation of m1 of B.
B objB = new A();
objB.m1();
If we need to implement both separately, we need to mention interface with method name like this..
class A : B, C
{
void B.m1()
{
throw new NotImplementedException();
}
void C.m1()
{
throw new NotImplementedException();
}
}
Vishwakant TripathiPosted Oct 16, 2021, 2:32 AM EDT
Use B.m1() and C.m1()
sarita rajputPosted Jul 4, 2016, 12:19 AM EDT
Use B.m1() and C.m1()
sarita rajputPosted Jul 4, 2016, 12:19 AM EDT

