ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to demonstrate the MustInherit class

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

Here, we will create a MustInherit class Sample1 and then inherit the Sample1 class into Sample2 class. We cannot create the object of MustInherit class.

Program/Source Code:

The source code to demonstrate the MustInherit class is given below. The given program is compiled and executed successfully.

'VB.net program to demonstrate the "MustInherit" class.

Module Module1
    MustInherit Class Sample1
        Sub Fun1()
            Console.WriteLine("Fun1() called")
        End Sub
    End Class

    Class Sample2
        Inherits Sample1
        Sub Fun2()
            Console.WriteLine("Fun2() called")
        End Sub

    End Class

    Sub Main()
        'We cannot create the object of mustinherit class, 
        'the below statement will generate an error
        'Dim S1 As New Sample1()

        Dim S2 As New Sample2()
        S2.Fun1()
        S2.Fun2()
    End Sub
End Module

Output:

Fun1() called
Fun2() called
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1. Here, we created a Sample1 class, which is declared as MustInherit. Sample1 contains the Fun1() method and then we inherited the Sample1 class into Sample2 class. We cannot create the object of MustInherit class in the VB.Net.

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 the Fun1(), Fun2() methods that will print an 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.