VB.Net program to demonstrate the NotInheritable class

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

Here, we will create a NotInheritable class Sample1 and then create a normal class Sample2. A NotInheritable class cannot be inherited in any class.

Program/Source Code:

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

' program to demonstrate the "NotInheritable" class.
Module Module1
    NotInheritable Class Sample1
        Sub Fun1()
            Console.WriteLine("Fun1() called")
        End Sub
    End Class

    Class Sample2
        'We cannot inherit a NotInheritable class 
        'inside the VB.NET program.
        'Inherits Sample1
        Sub Fun2()
            Console.WriteLine("Fun2() called")
        End Sub

    End Class

    Sub Main()
        Dim S1 As New Sample1()
        Dim S2 As New Sample2()

    End Sub
End Module


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


In the above program, we created a module Module1. Here, we created a NotInheritable class Sample1. We cannot inherit a NotInheritable class inside any class in VB.Net program. Then we created a Sample2 class that contains a method Fun2().

At last, we created a Main() function, which is the entry point for the program, here we created the objects of Sample1 and Sample2 class and called the Fun1(), Fun2() methods that will print an appropriate message on the console screen.

VB.Net Basic Programs »



Comments and Discussions




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

© some rights reserved.