VB.Net Program to Demonstrate the Parameterized Constructor

You are currently viewing VB.Net Program to Demonstrate the Parameterized Constructor

VB.Net program to demonstrate the parameterized constructor

'VB.net program to demonstrate the parameterized constructor.

Module Module1
    Class Sample
        Private num As Integer

        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 obj As New Sample(20)
        obj.Print()
    End Sub
End Module

Output

Parameterized constructor called to initialize data members
Value of num: 20
Press any key to continue . . .

Ranjith Kumar

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

Leave a Reply