什么是父类的子类和派生的基类的VB.NET或C#的区别? [英] What is the difference between a child of a parent class and the derived of a base class in VB.NET or C#?
问题描述
问这个问题后的 调用需要输入在VB.NET基类或C#一个派生类实例的方法> 的堆栈溢出,笔者获悉问这个问题的时候,我已经使用了错误的条款。我用了父,并在那里我应该用基地和导出,而不是子。
我一直无法找到的一个很好的说明。区别
这是我知道(或认为我知道)为止:
一个父类包含子类。凡作为一个派生类从基类继承。
它们是相似的,因为孩子(或派生)可以访问的父母(或底部)的属性和方法(如允许)。
他们是不同的,因为你可以参考的形式子类物业 Parent.Child.Property
。虽然你不能做到这一点与派生类。
什么是在应该一个比其他?
使用什么情况的差异,< DIV CLASS =h2_lin>解决方案
的父的和的孩子的更抽象的关系。它们被用来描述层次结构,从而可以在各种树木被使用(或有时DAG)的。结果
类继承的树就是这样的树,所以称他们的父和孩子的没有错。结果
这个术语通常与其他种类的树木,比如嵌套GUI控件,目录结构,...
$ b
的基和派生的仅用于继承,从而更精确。这个术语是首选,因为它是那么模糊。
After asking the question Call a method that requires a derived class instance typed as base class in VB.NET or C# on Stack Overflow, I was informed that I had used the wrong terms when asking the question. I had used "parent" and "child" where I should have used "base" and "derived" instead.
I have been unable to find a good description of the difference.
This is what I know (or think I know) so far:
A parent class contains the child class. Where as a derived class inherits from a base class.
They are similar because the child (or derived) can access the parents (or base) properties and methods (where allowed).
They are different because you can refer to a property of the child class in the form of Parent.Child.Property
. Whereas you cannot do that with a derived class.
What is the difference and in what situation should one be used over the other?
parent and child are more abstract relations. They are used to describe hierarchy, and thus can be used in all kinds of trees (or sometimes DAGs).
The tree of class inheritance is one such tree, so calling them parent and child is not wrong.
This terminology is often used with other kinds of trees, such as nested GUI controls, directory structures,...
base and derived is used only for inheritance, and thus more precise. This terminology is preferred, since it's less ambiguous.
这篇关于什么是父类的子类和派生的基类的VB.NET或C#的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!