Doubts in Multiple inheritance in .net

本小妞迷上赌 提交于 2019-12-01 12:13:35

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5244693/doubts-in-multiple-inheritance-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!