ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to demonstrate the abstract class

Here, we are going to demonstrate the abstract class in VB.Net.
Submitted by Nidhi, on December 28, 2020

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 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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.