By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,892 Members | 1,112 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,892 IT Pros & Developers. It's quick & easy.

C# inheritance

P: n/a
AJ
Is multiple inheritance is possible in C#?
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
NK
No

"AJ" wrote:
Is multiple inheritance is possible in C#?

Nov 16 '05 #2

P: n/a
NK
No

"AJ" wrote:
Is multiple inheritance is possible in C#?

Nov 16 '05 #3

P: n/a
KH
One could argue yes, as all types implicitly inherit from System.Object

So all classes, except System.Object presumably, inherit from System.Object

Therefore any class that inherits from another is inheriting from multiple
types.

But generally you would say "no"
"NK" wrote:
No

"AJ" wrote:
Is multiple inheritance is possible in C#?

Nov 16 '05 #4

P: n/a
I am going to answer yes to make you think and give you a big headache
:).
C# supports multiple inheritance of interfaces and single inheritance of
an
implementation hierarchy. An interface in C# is equivalent to a pure
virtual
_class_ in C++. Many major C++ frameworks are based on multiple
inheritance of pure virtual classes.

If you absolutely must have multiple inheritance of implementation you
can
do this with a technique called simulated MI.

Regards,
Jeff
Is multiple inheritance is possible in C#?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

P: n/a
This is inaccurate. Multiple inheritance, in O-O terms, means that a
class has two parents from different branches in the class hierarchy,
not merely that it has a parent that in turn has another parent.

All that "all classes inherit from object" means is that the
inheritance hierarchy begins with a single parent class, object, that
itself has no parent. All classes in .NET derive either from object, or
derive from a class that derives (directly or indirectly) from object.

Class B that derives from class A, then, does not derive from A _and_
object. It merely derives from A, which has, somewhere up the
hierarchy, object as an ancestor and so inherits object's methods by
the usual single-inheritance mechanism.

NK: Sorry. C# is like Java: it supports single inheritance only when it
comes to classes. Interfaces provide polymorphic behaviour outside the
hierarchical class-inheritance structure, but the downside with
interfaces is that you have to implement every method in every class
that implements the interface.

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.