C# inheritance

G

Guest

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"
 
J

Jeff Louie

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#?
 
B

Bruce Wood

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top