Abstract Class in VB.NET
What is an Abstract Class in VB.NET?
Explanation
Abstract Class in vb.net 2008
Abstract Classes in VB.net are classes that cannot be instantiated, but can implement any number of members. The
Abstract Classes are declared using the keyword
MustInherit. Overideable members should be declared inside the
abstract class using the keyword
MustOverride that are instantiated in the derived class by overriding them.
Example:
Module Module1
Public MustInherit Class student
Public id As Integer
Public Function Add() As Integer
Dim i, j As Integer
i = 100
j = 200
Console.WriteLine("Result:" & (i + j))
End Function
Public MustOverride Sub Disp()
End Class
Class Shed
Inherits student
Public Overrides Sub Disp()
Console.WriteLine("Instantiating the abstract member
function disp() in the derived class.")
End Sub
End Class
Sub Main()
Dim obj As New Shed
obj.Add()
obj.Disp()
Console.Read()
End Sub
End Module
Result:
Result:300
Instantiating the abstract member function disp()
in the derived class
Description:
In the above example, the Absract class
'student' acts as a base class and the abstract member
of the class
'Disp()' is overidden inside the derived class
Shed.