JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Using the MustInherit Keyword (Creating Abstract Classes)

The MustInherit keyword is used to declare a class that cannot be instantiated and can be used only as a base class, also called an abstract base class. For example, in the Inheritance example on the CD-ROM, I derive two classes, Fish and Dog, from the Animal class. To make Animal an abstract class, all I have to do is to use the MustInherit keyword:

Public MustInherit Class Animal
    Protected MainForm As Form1
    Public Sub New(ByVal form1 As Form1)
        MainForm = form1
    End Sub

    Public Overridable Sub Breathing()
        MainForm.TextBox1.Text = "Breathing..."
    End Sub
End Class

Public Class Dog
    Inherits Animal
        
End Class

Public Class Fish
    Inherits Animal
        
End Class
Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor