Amit
Amit

Reputation: 623

Doubts in Multiple inheritance in .net

We know that all the classes are inherited from the object class in .net. Say we create a class named ClassA. Then we create another class named ClassB that is inherited from ClassA. Isn't this multiple inheritance, because ClassB inherited from both Object class and ClassA? Doesn't this break the rule that C#.net doesn't support multiple inheritance?

Upvotes: 0

Views: 361

Answers (2)

user47589
user47589

Reputation:

You do not understand what multiple inheritance is. From wikipedia:

Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass.

From wikipedia's entry on superclass:

A superclass, base class, or parent class is a class from which other classes are derived. The classes that are derived from a superclass are known as child classes, derived classes, or subclasses.

In your example, ClassA inherits from object. ClassB inherits from ClassA. ClassA is the superclass of ClassB. Object is not a superclass of ClassB. Your example is not multiple inheritance. There is one parent, one child.

Upvotes: 2

Frederik Gheysels
Frederik Gheysels

Reputation: 56934

No, you do not break the rule. Since ClassA is an object, it does not mean that you're inheriting from 2 different classes. You're inheriting from ClassA, and thereby taking all the characteristics from the 'inheritance chain' with it.
You're not inheriting from 2 different types, since ClassA is an object.

Upvotes: 1

Related Questions