Polymorphism using Abstract Classes in Visual Basic.NET 2005 - Defining and implementing abstract classes in Visual Basic 2005: child class (Page 4 of 6 )
In the previous section, a class named "Shape" is defined with "MustInherit" as it has one method declared with "MustOverride" (an abstract method). In this section, I shall create child classes (sub classes) for the parent class (super class) "Shape."
Let us start with the following:
Public Class Rectangle
Inherits Shape
Public Sub New(ByVal l As Double, ByVal b As Double)
MyBase.New(l, b)
End Sub
Public Overrides Function GetArea() As Double
Return Me.X * Me.Y
End Function
End Class
In the above "Rectangle" class, we have a constructor with the following statement:
MyBase.New(l, b)
The above statement calls the constructor of the super class; in this case, it is constructor of "Shape." Finally, the abstract method is implemented with the same signature defined in the "Shape" class as follows:
Public Overrides Function GetArea() As Double
Return Me.X * Me.Y
End Function
Similarly, the "EquiTriangle" and "Square" can be defined as described in the next section.
Next: Defining and implementing abstract classes in Visual Basic 2005: child classes continued >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee