mukul chakravarty

mukul chakravarty

  • NA
  • 25
  • 31.5k

C sharp multiple inheritence...

May 27 2013 6:30 PM

 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();

    }

}

 

 


Answers (3)