Write a program to demonstrate the use of Constructor in Vb.net

Module Module1
    Public Class Sample
        Private a As Integer
        Public Sub New(ByVal setval As Integer)
            a = setval
        End Sub
        Public Function disp()
            Return a
        End Function
    End Class
    Sub Main()
        Dim d As New Sample(5)
        Console.Write("Value of a initilized to:")
        Console.Write(d.disp())
        Console.ReadKey()


    End Sub

End Module

O/P:
Value of a initilized to 5

Comments