VB.Net Program to Create Multiple Objects of the Class

You are currently viewing VB.Net Program to Create Multiple Objects of the Class

VB.Net program to create multiple objects of the class

'VB.Net program to create multiple objects of the class.

Class Sample
    Private num1 As Integer
    Private num2 As Integer

    Public Sub SetValues(ByVal n1 As Integer, ByVal n2 As Integer)
        num1 = n1
        num2 = n2
    End Sub

    Public Sub PrintValues()
        Console.WriteLine("Num1: " & num1)
        Console.WriteLine("Num2: " & num2)
    End Sub
End Class

Module Module1
    Sub Main()
        Dim obj1 As New Sample()
        Dim obj2 As New Sample()

        Console.WriteLine("Object1 data:")
        obj1.SetValues(10, 20)
        obj1.PrintValues()

        Console.WriteLine(vbCrLf & "Object2 data:")
        obj2.SetValues(30, 40)
        obj2.PrintValues()
    End Sub
End Module

Output

Object1 data:
Num1: 10
Num2: 20

Object2 data:
Num1: 30
Num2: 40
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