没有抽象方法的抽象类 [英] Abstract class with no abstract methods
问题描述
参考C#,可以定义不包含抽象方法的抽象类,然后将类定义为ABSTRACT有什么用?
With refrence to C#, it is possible to define abstract class containing no abstract methods, then whats the use of defining class as ABSTRACT?
推荐答案
基本上,我的经验法则是,在必须继承要实例化的类时,应始终定义抽象类。因为抽象类本身不能。
Basically, I use as a rule of thumb that you should always define classes abstract when they MUST be inherited to be instantiated. Because abstract classes themselves cannot.
例如。假设您有一个建筑类,它是抽象的。然后必须通过派生类(例如,银行或房屋)来实例化它。 Building类中没有抽象方法这一事实与它是否抽象无关。
For example. Say you have a Building class, which is abstract. It must then be instantiated through a derived class, for example, a Bank or House. The fact that there are no abstract methods in the Building class has nothing to do with it being abstract or not.
这篇关于没有抽象方法的抽象类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!