An two interface has got same method names, how can you access differently.

 Posted by Self-Innovator on 1/12/2015 | Category: OOPS Interview questions | Views: 847 | Points: 40
Answer:

Declare two interfaces with same method names
interface myInterface1

{
void m1();
}
interface myInterface2
{
void m1();
}

Implement the Interface method in Base Class

public class myClass : myInterface1, myInterface2
{
public void m1()
{
Console.WriteLine("m1 accessed");
}
}

Create an instance of base class & references of interface classes

class Program
{
static void Main(string[] args)
{
myClass mc = new myClass();
myInterface1 mi1 = (myInterface1)mc;
myInterface2 mi2 = (myInterface2)mc;
mc.m1();
mi1.m1();
mi2.m1();
Console.ReadKey();
}
}


Source: Mindtree Interview Question | Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response