Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the abstract class
By Nidhi Last Updated : November 11, 2024
Abstract Class in VB.Net
Here, we will create an abstract class using the MustInherit keyword. An abstract class contains an abstract method. Here abstract methods are created using the MustOverride keyword.
Program/Source Code:
The source code to demonstrate the abstract class is given below. The given program is compiled and executed successfully.
VB.Net code to demonstrate the example of abstract class
'VB.net program to demonstrate the abstract class.
Module Module1
MustInherit Class Sample1
MustOverride Sub Fun1()
MustOverride Sub Fun2()
End Class
Class Sample2
Inherits Sample1
Overrides Sub Fun1()
Console.WriteLine("Override method Fun1() called")
End Sub
Overrides Sub Fun2()
Console.WriteLine("Override method Fun2() called")
End Sub
End Class
Sub Main()
Dim S As New Sample2()
S.Fun1()
S.Fun2()
End Sub
End Module
Output:
Override method Fun1() called
Override method Fun2() called
Press any key to continue . . .
Explanation:
In the above program, we created a module Module1 that contains two classes Sample1 and Sample2.
Here, Sample1 is an abstract class that contains two abstract methods. We cannot create the object of the abstract class. Here, we override the methods of Sample1 class into Sample2 class.
At last, we created a Main() function, which is the entry point for the program, here we created the object of Sample2 class, and called both methods Fun1() and Fun2(), which will print the appropriate message on the console screen.
VB.Net Basic Programs »