VB.Net program to demonstrate the shared methods

Here, we are going to demonstrate the shared methods in VB.Net.
Submitted by Nidhi, on December 28, 2020 [Last updated : March 06, 2023]

Shared methods in VB.Net

Here, we will create a class Sample with shared methods. Shared methods are class methods there is no need to create the object to call shared methods.

Program/Source Code:

The source code to demonstrate the shared methods is given below. The given program is compiled and executed successfully.

VB.Net code to demonstrate the example of shared methods

'VB.net program to demonstrate the Shared methods.

Module Module1
    Class Sample
        Shared Sub Fun1()
            Console.WriteLine("Sample.Fun1() called")
        End Sub
        Shared Sub Fun2()
            Console.WriteLine("Sample.Fun2() called")
        End Sub
    End Class

    Sub Main()
        Sample.Fun1()
        Sample.Fun2()
    End Sub
End Module

Output:

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

Explanation:

In the above program, we created a module Module1 that contains a class Sample. In the Sample class, we created two shared methods fun1() and fun2(). To call the shared methods we are not required to create an object.

At last, we created a Main() function, which is the entry point for the program, here we called both shared method that will print the appropriate message on the console screen.

VB.Net Basic Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.