VB.NET tutorial-Create objects

Object-Oriented Programming (OOP)

Create objects

To access public members of the class, you must create its object. The object can be created by using the New keyword.

Dim stu As New Student

Accessing a class’s public members through objects

To access public members of a class, you must write its name of object followed by dot sign(.) and the names of its members.

Module Module1
    Sub Main()
        Dim st As New Student 'create object
        st.setnumber()' accessing members
    End Sub
    Class Student
        Private stnumber As Integer
        Private stname As String
        Private stsex As String
        Public Sub setnumber()
            Console.WriteLine("Enter student's number:")
            stnumber = CInt(Console.ReadLine)
        End Sub
        Public Sub getnumber()
            Console.WriteLine("Student's number is:" & stnumber)
        End Sub
    End Class
End Module

This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.