VB.Net Program to Demonstrate the Constructor Chaining

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

VB.Net program to demonstrate the constructor chaining

'VB.net program to demonstrate the constructor chaining.

Module Module1
    Class Sample
        Private num As Integer

        Public Sub New()
            Console.WriteLine("Default or no argument constructor called")
        End Sub
        Public Sub New(ByVal n As Integer)
            Me.New()
            Console.WriteLine("Parameterized constructor called")
            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

Default or no argument constructor called
Parameterized constructor called
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