About Me

My photo
Cranbourne, Victoria, Australia
D.O.B: 6/8/1991 makes me 17
Live in Cranbourne
Go to tafe 3 days a week :)
Monday, Tuesday and Fridays...
Come say Hi? :)

Myspace is www.myspace.com/c0urtsxx
Msn is: cawts.x@hotmail.com

Followers

Monday, March 23, 2009

VB.NET Classes and Ojects

Classes and Objects

Classes are types and Objects are instances of the Class. Classes and Objects are very much related to each other. Without objects you can't use a class. In Visual Basic we create a class with the Class statement and end it with End Class. The Syntax for a Class looks as follows:

Public Class Test

----- Variables
-----Methods
-----Properties
-----Events

End Class



The above syntax created a class named Test. To create a object for this class we use the new keyword and that looks like this: Dim obj as new Test(). The following code shows how to create a Class and access the class with an Object. Open a Console Application and place the following code in it.

Module Module1
Imports System.Console

Sub Main()
Dim obj As New Test()
'creating a object obj for Test class
obj.disp()
'calling the disp method using obj
Read()
End Sub

End Module

Public Class Test
'creating a class named Test
Sub disp()
'a method named disp in the class
Write("Welcome to OOP")
End Sub
End Class

No comments:

Post a Comment