Interviews - C# Corner

vinay gn
Why their is no Multiple Inheritance in .Net,? for instance if the multiple inheritance is allowed in .Net what might be the problem it poses?
By vinay gn in ASP.NET onJun 15 2012
  • Piyush Mani
    Jun, 2012 29

    In some situation Multiple Inheritance may create a problem, know as Diamond Problem. How: Lets say, I have a class Axx with a method called Test(). Now I have another classes as class Bxx and class Cxx, which is inheriting class Axx, and overriding method Test() differently in both the classes (Bxx & Cxx). Now I have another class as class Dxx, which is inheriting class Bxx and class Cxx. Now I want to create an instance of class Dxx in my main function and want to call method Test(). Now it will create an ambiguity that which function will be called (function overridden from class Bxx or class Cxx). This is known as Diamond Problem. class Axx { public:virtual void Test(){printf("This is my clas A Testing");} };class Bxx : public Axx { public:void Test(){printf("This is my clas B Testing");} };class Cxx : public Axx { public:void Test(){printf("This is my clas C Testing");} };class Dxx : public Bxx, public Cxx { public:void Testing(){printf("This is my clas C Testing");} };int _tmain(int argc, _TCHAR* argv[]) {Dxx obj;obj.Test(); //Ambiguous error will occur.getch();return 0; }

    • 0

Most Popular Companies

Most Popular Job Functions