.NET Interview questions for Interfaces:- If A class inherits from multiple interfaces and the interfaces have same method names. How can we provide different implementation?.

 Posted by articlesmaint on 2/12/2011 | Category: .NET Framework Interview questions | Views: 9208

This is again one those typical .NET Interview questions which move around interfaces to confuse the developer.

For providing different implementation you can qualify the method names with interface names as as shown below. A reference to I1 will display "This is I1" and reference to I2 will display "This is I2". Below is the code snippet for the same.

interface I1 
void MyMethod();

interface I2 

void MyMethod(); 

class Sample : I1, I2 

public void I1.MyMethod() 

Console.WriteLine("This is I1"); 
public void

Console.WriteLine("This is I2"); 


50 .NET Interview questions and answers 


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response