Bagikan melalui


Override Modifiers

You can use the NotOverridable and MustOverride modifiers in a base class to control how derived classes override its properties and methods.

The NotOverridable modifier defines a method of a base class that cannot be overridden in derived classes. All methods are NotOverridable unless marked with the Overridable modifier. You can use the NotOverridable modifier when you do not want to allow an overridden method to be overridden again in a derived class.

Methods defined with the MustOverride modifier have no implementation in the base class and must be implemented in derived classes. Classes that contain MustOverride methods must be marked with the MustInherit modifier.

Example

MustInherit Class BaseClass
    Public MustOverride Sub aProcedure()
End Class 

Class DerivedClass
    Inherits BaseClass
    Public NotOverridable Overrides Sub aProcedure()
        ' Override a procedure inherited from the base class 
        ' and mark it with the NotOverridable modifier so that  
        ' it cannot be overridden in classes derived from this class. 
    End Sub 
End Class

See Also

Concepts

Overloaded Properties and Methods