Create Classes in VB.NET

Learn how to create a class in VB.Net?

Explanation

Classes in VB.NET 2008

Classes in VB.net is type used to create data or objects that are instances of a class. Objects and classes are so closely associated with each other, so that classes can be used only if it contains objects.
The Scope of usage of classes and the objects are based on the access types used when they are declared as Public, Private, Friend and Protected.
Example:

Module Module1
Public Class Add
Dim i, j As Integer
Public Sub Display()
System.Console.WriteLine("Enter First Integer:")
i = Console.ReadLine()
System.Console.WriteLine("Enter Second Integer:")
j = Console.ReadLine()
Console.WriteLine("Result of Addition is:" & (i + j))
End Sub
End Class
Sub Main()
Dim add1 As New Add
add1.Display()
Console.Read()
End Sub
End Module
Result:

Enter First Integer:
2
Enter Second Integer:
3
Result of Addition is:
5
Description:

In the above example, class Add is declared as 'Public', so that the method display is derived and used by creating an instance add1 inside sub main().

Visual Basic Tutorial


Ask Questions

Ask Question