GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Microsoft  >  C#
Go To First  |  Previous Question  |  Next Question 
 C#  |  Question 337 of 430    Print  
Why multiple Inheritance is not possible in C#?
(Please do not answer like this-It is possible through Interfaces.)

  
Total Answers and Comments: 7 Last Update: March 25, 2007     Asked by: Rohit Sharma 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
April 28, 2006 02:58:01   #1  
Sunil        

RE: Why multiple Inheritance is not possible in C#?
When we use the Multiple inherutance .. we use more than one class.....ok. Lets one condition class A and class B are base classes and class c is is multiple inherting it ok........and where class c is inheriting a function ......ok it may be possible that this function with same name and same signature can present in both class A and Class B .. That time how the compiler will know ..that which function it should take wherether from class A or class B.So this time Multiple inheritanc won't work .So avoiding this problem we use Interface..... what is interface ... means in interface we just declare a function ...ok and in the derived class we give the definition as per the requirement...means function should be abstract ... and in interface all funcion[method] should abstract.
 
Is this answer useful? Yes | No
April 28, 2006 10:55:46   #2  
Hasham        

RE: Why multiple Inheritance is not possible in C#?
To avoid name collision. Multiple Inheritence can have many classes and methods , and its quite possible that they can have save name " say a save function in two different classe name can be Save() but implementation can be different". The derived class will have problem accessing the correct function.
 
Is this answer useful? Yes | No
May 02, 2006 07:15:46   #3  
Rohit Sharma        

RE: Why multiple Inheritance is not possible in C#?

Then how it was working fine in C++??


 
Is this answer useful? Yes | No
May 08, 2006 09:09:31   #4  
NageshwaraRao        

Why multiple Inheritance is not possible in C#?

Hi Dear Friends..!

Multiple Inheritance is possible in C++, but its not possible in Java, and C#.

what we are read above those are all we know, but as per my knowledge, in C++ to resolve multiple inheritance we are using "this pointer". But in C# there is no pointer concept. In such way, the architectures using the interface concept. To resolving the ambiguity "this pointer" concept used in c++.

Offcourse it not absolutely correct, but its my idea only. If you are agree with my view then follow it, else leave it.


 
Is this answer useful? Yes | No
September 01, 2006 04:37:02   #5  
Rajsekhar        

RE: Why multiple Inheritance is not possible in C#?

Hi

  Your answer is good but I have doubt, I can call the Method is class as A.fun1(), B.fun1() in derived class C. In that way we can use the multiple inheritance concept in dotnet.  


 
Is this answer useful? Yes | No
September 17, 2006 16:38:06   #6  
jonathan        

RE: Why multiple Inheritance is not possible in C#?
Multple inheritance is coneceptually wrong. It shouldn't be allowed in any language. Inheritance is the strongest relationship that can be expressed in OO languages. It's used to express IS-A relationship. Aggregation is used to express IS CONSTRUCTED IN TERMS OF. If you're using multiple inheritance in C++ then you're design is wrong and you probably want to use aggregation. On the other hand it's plausible to want to use multiple interfaces. For instance you might have a class wheel and a class engine. You could say that your class car inherits from wheel and from engine but that's wrong. In fact car aggregates wheel and engine because it is built in terms of those classes. If wheel is an interface and engine is an interface then car must inherit both of these interfaces since it must implement the functionaity of wheel and engine .On this basis we can see that multiple inheritance for classes should not be allowed because it promotes mis-use of the strong IS-A relationship. C# enforces the correct concepts whilst C++ allows mis-use. multiple interface inheritance is permissible and C# allows this. It's all to do with properly understanding OO concepts.Try reading Exceptional C++ by Herb Sutter to get a good discussion of the correct and incorrect uses of inheritance.
 
Is this answer useful? Yes | No
March 25, 2007 04:47:12   #7  
Ravi Kumar        

RE: Why multiple Inheritance is not possible in C#?
Jonathan is right. Absolute Multiple Inheritance is not possible in c# but partially it supports multiple  inheritance  by the use of Interfaces. As interfaces force a class to implement same type of behaviour (as defined in interface) which classes implements that interface.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape