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.

如果OverridableNotOverridable修飾詞未指定,預設值取決於是否屬性或方法會覆寫基底類別屬性或方法。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.

您只能在屬性或程序宣告陳述式中使用 OverridableYou can use Overridable only in a property or procedure declaration statement.

結合的修飾詞Combined Modifiers

您無法指定Overridable或是NotOverridablePrivate方法。You cannot specify Overridable or NotOverridable for a Private method.

您無法指定Overridable連同MustOverrideNotOverridable,或Shared相同宣告中。You cannot specify Overridable together with MustOverride, NotOverridable, or Shared in the same declaration.

因為覆寫項目可隱含覆寫,您無法結合 OverridableOverridesBecause 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 陳述式Property Statement

Sub 陳述式Sub Statement

另請參閱See also