Why multiple inheritance is not possible in c#
Answers were Sorted based on User's Feedback
Answer / saurabh
Suppose, you have class A, which implements a method Show().
This class is now Inherited by Class B and Class C.
Now both B,C will have Show available to them or may be they
have overridden the functionality of Show() defined by Class
A. So far this is fine.
Now If I have Class D inheriting from Class B and Class C.
Which Show() method will class D be using? How many
implementations of Show will be available there for class D?
This is the problem.
Is This Answer Correct ? | 55 Yes | 11 No |
Answer / gp_bellamkonda
When we use the Multiple inherutance,we use more than one
class.Suppose class A and class B are base classes and
class c is is multiple inherting it.it may be possible that
this function with same name and same signature can present
in both class A and Class B .At this time how the compiler
will know which function it should take wherether from
class A or class B.
So Multiple inheritance won't work.
To avoid this problem we use Interface..... it means in
interface we just declare a function 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 Correct ? | 36 Yes | 6 No |
Answer / kanan
There is no definitive answer to this question. It is a
matter of taste.
There is the classic diamond problem encountered in multiple
inheritance, in which class D inherits from both B and C,
which both inherit from A.
A
/ \
B C
\ /
D
So which copy of A does D get? The one from B, the one from
C? Both?
Is This Answer Correct ? | 18 Yes | 8 No |
Answer / shrikant narayanrao khode
Reason :
Every class inherit ToString() method.
class A ---> ToString()
class B ---> ToString()
-----------------------------
class C :A,B
Toatl ToString() method will be ----> 2
It is going to raise ambiguity problem.
Thats why Multiple inheretance is not possibe.
Is This Answer Correct ? | 5 Yes | 0 No |
Answer / satya
let me explain clearly,,,, suppose there is a class called
A(base class)and it has a method Print(). now I am
implementing heirarchical inheritance and derived classes
are B, C and D. now in three derived classes that print() is
there. now the problem is form which class (from derived
classes for first class A) i have to take print() ?
If signature is same then no problem, if it differs what is
the result?
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / sravanthi
Deriving a new class from more than 1 base class (or) old
class is called multiple inheritance.but c# does not
supports it.but we can implement multiple concept by using
interfaces.
Is This Answer Correct ? | 3 Yes | 17 No |
What is the difference between dll and lib?
Is c# scripting language?
What is the implicit name and type of the parameter that gets passed into the class set method?
How do I create a multilanguage, single-file assembly?
What is difference between const and static in c#?
Is linkedhashset synchronized?
What are circular references?
HOw to judge a person for a team if you are allowed to ask only 2 questions to him?
Differentiate between object pooling and connection pooling in c#?
Can a class be protected in c#?
What is interface used in c#?
Why we use delegates in c#?