0% found this document useful (0 votes)
211 views3 pages

Sub Dim As New: Syco Console Syco Console

The document discusses implementing a program in VB.NET to demonstrate the use of class constructors and destructors. It provides sample code to call a constructor when an object is created and a destructor when the object is destroyed. It also includes sample output and questions related to constructors and destructors.

Uploaded by

68 DEEPAK GAUND
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
211 views3 pages

Sub Dim As New: Syco Console Syco Console

The document discusses implementing a program in VB.NET to demonstrate the use of class constructors and destructors. It provides sample code to call a constructor when an object is created and a destructor when the object is destroyed. It also includes sample output and questions related to constructors and destructors.

Uploaded by

68 DEEPAK GAUND
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical No.

18: Implement a Program For Class Constructor and Destructor To De-Allocate


Memory.

Practical No 18

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


 https://docs.microsoft.com/en-us/dotnet/visual-basic/language-
reference/statements/function-statement
 https://www.tutorialspoint.com/vb.net/vb.net_functions.htm

XI. Program Code


1. Write a program to demonstrate the use of constructor & destructor.
 A) Constructor-
Module Module1
Sub Main()
Dim obj As New syco
obj.show()
Console.ReadLine()
End Sub
Public Class syco
Public Function show()
Console.WriteLine("This is base class")
End Function
Sub New()
Console.WriteLine("Constructor Executed")
End Sub
End Class
End Module

OUTPUT:
Constructor Executed
This is base class

Module Module1
Sub Main()
Dim obj As New syco
obj.show()
End Sub
End Module
Public Class syco
Public Function show()
Console.WriteLine("This is base Class")
End Function
Protected Overrides Sub Finalize()
Console.WriteLine("Destructor executing here")
Console.ReadLine()
End Sub
End Class

GUI Application Development using VB.Net (22034) Page 1


Practical No.18: Implement a Program For Class Constructor and Destructor To De-Allocate
Memory.

OUTPUT:
This is base class
Destructor executing here

XII. Results (output of the program)


a. Constructor Executed
This is base class
b. This is base class
Destructor executing here

XIII. Practical related Questions


1. Find output in following code.
 40

2. Find Error in following code.


Imports System.Console
Module Module1
Sub Main()
Dim obj As New Destroy()
End Sub
End Module
Public Class Destroy
Protected Overrides Finalize()
Write(“VB.NET”)
Read()
End Sub
End Class
 Error 1 'Overrides' is not valid on a member variable declaration.
Warning 2 variable 'Finalize' conflicts with sub 'Finalize' in the base class 'Object' and
should be declared 'Shadows'.
Error 3 Declaration expected.
Error 4 Declaration expected.
Error 5 'End Sub' must be preceded by a matching 'Sub'.

GUI Application Development using VB.Net (22034) Page 2


Practical No.18: Implement a Program For Class Constructor and Destructor To De-Allocate
Memory.

XIV. Exercise
1. Implement a program to display any message at run time.(Using Constructor).
 Module Module1
Sub Main()
Dim obj As New sample
obj.display()
Console.ReadLine()
End Sub
Class sample
Public Sub New()
Console.WriteLine("This is Constructor")
End Sub
Sub display()
Console.WriteLine("This is Method")
End Sub
End Class
End Module

Output:

2. Implement a program to calculate area of circle using parameterized constructor.


 Module Module1
Sub Main()
Dim obj As New circle(2)
obj.area()
Console.ReadLine()
End Sub
Class circle
Dim p As Double = 3.14
Dim r, a As Double
Public Sub New(ByVal i As Integer)
r = i
End Sub
Sub area()
a = p * r * r
Console.WriteLine("Area of Circle = " & a)
End Sub
End Class
End Module

OUTPUT:
Area of Circle = 12.56

GUI Application Development using VB.Net (22034) Page 3

You might also like