The following code is an example of achieving multiple class inheritance through the use of interfaces. My question is- What if the two interfaces I and J had a method having same name i.e. show(). How would I now implement multiple class inheritance. I have tried to achieve this using the following code. But it is not working.
interface I
{
void show();
}
interface J
{
void show();
}
class A : I
{
public void show()
{
Console.WriteLine("I");
}
}
class B : J
{
public void show()
{
Console.WriteLine("J");
}
}
class C : I, J
{
A x = new A();
B y = new B();
public void I.show()
{
x.show();
}
public void J.show()
{
y.show();
}
}

VulpesRank #55 · 29.2K reputationPosted May 27, 2013, 2:52 PM EDT
However, there are two things to note about EII:
1. The implemented method cannot have an access modifier.
2. The implemented method can only be accessed via a reference to the interface concerned - you can't access it via a class reference.
Taking these points into account, the following is a working version of the program:
Raj KumarRank #25 · 44.2K reputationPosted May 27, 2013, 7:44 PM EDT
Pankaj PandeyRank #642 · 3.7K reputationPosted May 27, 2013, 8:43 PM EDT