Interview answers verified by specialists.

Find interview questions and answers on this website:


See right interview answers on 30 common job interview questions

Suppose that you have two interface named IFirstInterface and ISecondInterface.In both the interface same name method SameMethod() is available .As a developer you have to implement SameMethod() separately . How will you do that give example?

using System;
namespace CareerRideTest
{
public interface IFirstInterface
{
void SameMethod();
}

public interface ISecondInterface
{
void SameMethod();
}
class A : IFirstInterface, ISecondInterface
{
public A()
{
Console.WriteLine("I am in class A constructor ");
}

void IFirstInterface.SameMethod()
{
Console.WriteLine("I am in FirstInterface");
}
void ISecondInterface.SameMethod()
{
Console.WriteLine("I am in SecondInterface");
}
}

class MainClass
{
static void Main(string[] args)
{
IFirstInterface objFirst = new A();
objFirst.SameMethod();

ISecondInterface objSecond = new A();
objSecond.SameMethod();
Console.ReadKey();

}
}
}

Output:
I am in class A constructor
I am in FirstInterface
I am in class A constructor
I am in SecondInterface

Note:You cannot write as A objFirst = new A ();
in above program it will give error: