为什么不构造继承? [英] Why are constructors not inherited?
本文介绍了为什么不构造继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我猜有一些非常基本的关于C#继承,我不明白。会有人请赐教?
I'm guessing there's something really basic about C# inheritance that I don't understand. Would someone please enlighten me?
推荐答案
有时,子类时,要限制创建类的实例所需的条件。
Sometimes, when subclassing, you want to restrict the conditions required to create an instance of the class.
让我给你举个例子。如果确实类继承其超类的构造函数,所有的类就必须从对象
参数构造函数。显然,这是不正确的。
Let me give you an example. If classes did inherit their superclass constructors, all classes would have the parameterless constructor from Object
. Obviously that's not correct.
这篇关于为什么不构造继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文