在基类静态字段和派生类 [英] Static fields in a base class and derived classes
问题描述
在摘要
的基类,如果我们有一些静态
字段,然后会发生什么呢?
In an abstract
base class if we have some static
fields then what happens to them ?
时,其范围从它继承(从这个基类或只是类型继承的类每个子类有它的自己的副本的静态
从摘要
基类)的领域呢?
Is their scope the classes which inherit from this base class or just the type from which it is inheriting (each subclass has it's own copy of the static
field from the abstract
base class)?
推荐答案
<$ C C>静态成员是完全特定于 声明的类;子类没有得到单独副本。这里唯一的例外是仿制药;如果一个开放式泛型类型声明静态字段,字段是特定于该确切 组合的的类型参数构成的封闭泛型类型;即美孚< INT>
将有单独的静态字段美孚<串>
,假设字段上定义美孚< T>
static
members are entirely specific to the declaring class; subclasses do not get separate copies. The only exception here is generics; if an open generic type declares static fields, the field is specific to that exact combination of type arguments that make up the closed generic type; i.e. Foo<int>
would have separate static fields to Foo<string>
, assuming the fields are defined on Foo<T>
.
这篇关于在基类静态字段和派生类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!