Using Class Objects in Visual Basic

Objects are created to actually work with classes. Objected uses the variable and methods residing in classes.

Example

Module Module1

    Public Class Car
        Public name As String
        Public price As Decimal
        Public gears As Integer
    End Class

    Sub Main()

        Dim firstCar As New Car() ' creating object

        ' assign values to objects
        firstCar.name = "first car"
        firstCar.price = 100000.0
        firstCar.gears = 5

        Console.WriteLine(firstCar.name)
        Console.WriteLine(firstCar.price)
        Console.WriteLine(firstCar.gears)

        Console.ReadLine()
    End Sub

End Module

Output

first car
100000
5
Share

You may also like...