VB.Net program to demonstrate the constructor overloading

In case you are in trouble, our website is waiting to help you. VB.Net program to demonstrate the constructor overloading are going to find out through this article.

VB.Net program to demonstrate the constructor overloading

VB.Net program to demonstrate the constructor overloading

'VB.net program to demonstrate the constructor overloading.

Module Module1
    Class Sample
        Private num As Integer

        Public Sub New()
            Console.WriteLine("Default or no argument constructor called to initialize data members")
            num = 10
        End Sub
        Public Sub New(ByVal n As Integer)
            Console.WriteLine("Parameterized constructor called to initialize data members")
            num = n
        End Sub

        Public Sub Print()
            Console.WriteLine("Value of num: {0}", num)
        End Sub
    End Class
    
    Sub Main()
        Dim obj1 As New Sample()
        Dim obj2 As New Sample(20)

        obj1.Print()
        obj2.Print()
    End Sub
End Module
Default or no-argument constructor called to initialize data members
Parameterized constructor called to initialize data members
Value of num: 10
Value of num: 20
Press any key to continue . . .

Final Words

We hope you enjoyed the article VB.Net program to demonstrate the constructor overloading. The reason is that all your doubts will be resolved through this article.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment