-
Book Overview & Buying
-
Table Of Contents
Visual Basic Quickstart Guide
By :
In VB, abstract classes cannot be instantiated directly but serve as base classes for other classes. They are used to define a standard interface and behavior that derived classes must implement. Abstract classes can contain abstract (must be overridden) and non-abstract (can have default implementations) methods, properties, and fields.
To create an abstract class in VB, you can use the MustInherit keyword:
Public MustInherit Class Shape
Public MustOverride Sub Draw()
Public Sub GetArea()
Console.WriteLine("Calculating area...")
End Sub
End Class In this example, we defined an abstract class called Shape, with an abstract method called Draw, and a non-abstract method called GetArea. The Draw method is marked with the MustOverride keyword, indicating that any derived class must provide its implementation for the Draw method.
Next...