Overridable (Visual Basic)Overridable (Visual Basic)

指定属性或过程可由派生类中具有相同名称的属性或过程重写。Specifies that a property or procedure can be overridden by an identically named property or procedure in a derived class.

备注Remarks

Overridable修饰符允许在派生类中重写类中的属性或方法。The Overridable modifier allows a property or method in a class to be overridden in a derived class. NotOverridable修饰符防止在派生类中重写属性或方法。The NotOverridable modifier prevents a property or method from being overridden in a derived class. 有关详细信息,请参阅继承基础知识For more information, see Inheritance Basics.

如果 Overridable NotOverridable 未指定或修饰符,则默认设置取决于属性或方法是重写基类属性还是替代方法。If the Overridable or NotOverridable modifier is not specified, the default setting depends on whether the property or method overrides a base class property or method. 如果属性或方法重写基类属性或方法,则默认设置为 Overridable ; 否则为 NotOverridableIf the property or method overrides a base class property or method, the default setting is Overridable; otherwise, it is NotOverridable.

您可以隐藏或重写来重新定义继承的元素,但这两种方法之间的差异很大。You can shadow or override to redefine an inherited element, but there are significant differences between the two approaches. 有关详细信息,请参阅Visual Basic 中的隐藏For more information, see Shadowing in Visual Basic.

可以重写的元素有时称为虚拟元素。An element that can be overridden is sometimes referred to as a virtual element. 如果可以重写,但不一定是,则有时也称为具体元素。If it can be overridden, but does not have to be, it is sometimes also called a concrete element.

Overridable只能在属性或过程声明语句中使用。You can use Overridable only in a property or procedure declaration statement.

组合修饰符Combined Modifiers

不能 Overridable NotOverridable 为方法指定或 PrivateYou cannot specify Overridable or NotOverridable for a Private method.

不能 Overridable MustOverride NotOverridable Shared 在同一声明中同时指定、或。You cannot specify Overridable together with MustOverride, NotOverridable, or Shared in the same declaration.

由于重写元素是隐式可重写的,因此不能将 OverridableOverrides 组合到一起。Because an overriding element is implicitly overridable, you cannot combine Overridable with Overrides.

用法Usage

Overridable 修饰符可用于下面的上下文中:The Overridable modifier can be used in these contexts:

Function 语句Function Statement

Property StatementProperty Statement

Sub 语句Sub Statement

另请参阅See also