Programs of Vb.
Net
Develop a program to create class. Access
members of class using its object.
Module Module1
Sub Main()
Dim obj As New Test 'creating a object obj for Test Class
[Link]() 'Calling the disp method using obj
[Link]()
End Sub
End Module
Public Class Test
Sub disp()
[Link]("Welcome to [Link]")
End Sub
End Class
1. Write a program to identify Volume of Box Class, with three
data members, length, breadth and height.
Class Box
Module Module1
Public l, b, h As Integer
Sub Main()
Function volume(ByVal i As Integer, ByVal j As Integer, ByVal k As
Dim obj As Box = New Box() Integer)
Dim vol As Integer Dim v As Integer
vol = [Link](2, 4, 4) l=i
[Link]("Length =" & obj.l) b=j
[Link]("Breadth =" & obj.b) h=k
[Link]("Height =" & obj.h) v=l*b*h
[Link]("Volume =" & vol) Return v
[Link]() End Function
End Sub End Class
End Module
Implement a program to accept values from Combo Box and
Display average of this in message box using class.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]
[Link](5)
[Link](8)
[Link](6)
[Link](11)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim average As double = (Val([Link]) + Val([Link])) / 2
MsgBox("Average = " & average)
End Sub
End Class
Write a program to demonstrate the use of constructor &
destructor
Module1
Sub Main() OUTPUT:
Constructor Executed
Dim obj As New test
This is base class
[Link]()
[Link]()
End Sub
Public Class test
Public Function show()
[Link]("This is base class")
End Function
Sub New()
[Link]("Constructor Executed")
End Sub
End Class
End Module
Module Module1
Sub Main() OUTPUT: This is base class
Dim obj As New test Destructor executing here
[Link]()
End Sub
End Module
Public Class test
Public Function show()
[Link]("This is base Class")
End Function
Protected Overrides Sub Finalize()
[Link]("Destructor executing here")
[Link]()
End Sub
End Class
1. Implement a program to display any message at run
time.(Using Constructor).
Module Module1
Sub Main()
Dim obj As New sample
[Link]()
[Link]()
End Sub
Class sample
Public Sub New()
[Link]("This is Constructor")
End Sub
Sub display()
[Link]("This is Method")
End Sub
End Class
End Module
2. Implement a program to calculate area of circle using
parameterized constructor.
Module Module1 Class circle
Dim p As Double = 3.14
Sub Main()
Dim r, a As Double
Dim obj As New circle(2) Public Sub New(ByVal i As Integer)
[Link]() r=i
[Link]() End Sub
End Sub Sub area()
a=p*r*r
[Link]("Area of Circle = " & a)
End Sub
End Class
OUTPUT: Area of Circle = 12.56 End Module
Develop a Program for Inheritance
Module Module1
Sub Main()
Dim obj As New details
[Link]()
[Link]()
End Sub
End Module
Public Class student 'Base Class
Public branch As String = "Computer"
End Class
Public Class details Inherits student 'Derived Class
Public Function show()
[Link]("Branch = " & branch)
Return 0
End Function
End Class
Implement a program for inheritance where Student is Child Class and faculty is Base
class.(Take Appropriate variable in Base and Child class)
Sub Main()
Module Module1
Dim s As New student
Class faculty
[Link]()
Sub branch()
Dim b As String = "Computer" [Link]()
[Link]("Branch = " & b) [Link]()
End Sub End Sub
End Class End Module
Class student Inherits faculty
Sub year()
Dim y As String = "Second Year"
[Link]("Year = " & y)
End Sub
End Class
Implement a Program for Overloading &
overriding
Imports System
Module Program
Class c1
Overridable Sub hi()
[Link]("Old Method hi")
End Sub
End Class
Class c2
Inherits c1
Shared Sub main()
Dim o As New c2()
[Link]()
End Sub
Overrides Sub hi()
[Link]("New and Improved method hi")
End Sub
End Class
End Module
Imports System
Module Module1
Class overload
Dim r As Double
Public Overloads Sub area(ByVal r)
[Link]("Area of the Circle :")
[Link](1 / 3 * 3.14 * r * r * r)
End Sub
Dim length As Integer
Dim width As Integer
Public Overloads Sub area(ByVal length, ByVal width)
[Link](" Area of the Rectangle :")
[Link](length * width)
End Sub
End Class
Sub Main()
Dim r As New overload()
[Link](3.1)
[Link](4, 5)
End Sub
End Module