![]() ![]() | ||
You can specify if class members must be overridden, can be overridden, or may not be overridden, using the MustOverride, Overridable, and NotOverridable keywords, respectively. We've already see in the In Depth section of this chapter in the Inheritance example how to use the Overridable keyword to indicate that a method may be overridden:
Public Overridable Sub Breathing() MainForm.TextBox1.Text = "Breathing..." End Sub Public Overrides Sub Breathing() MainForm.TextBox1.Text = "Bubbling..." End Sub
You also can use MustOverride to indicate that derived classes must provide their own implementation of a method:
Public MustOverride Overridable Sub Breathing()
MainForm.TextBox1.Text = "Breathing..."
End Sub
Using MustOverride creates pure virtual, also called abstract, methods. These methods may not be used directly, but must be overridden; for example, a method that returns the programmer's name must be customized and is best created as an abstract method.
You also can indicate that a method may not be overridden (as for a method that returns copyright information) using the NotOverridable keyword:
Public NotOverridable Sub Breathing()
MainForm.TextBox1.Text = "Breathing..."
End Sub
![]() ![]() | ||