ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to demonstrate the destructor

Here, we are going to demonstrate the destructor in VB.Net.
Submitted by Nidhi, on December 25, 2020

Here, we will create a Sample class that contains the default constructor and destructor.

Program/Source Code:

The source code to demonstrate the destructor is given below. The given program is compiled and executed successfully.

'VB.net program to demonstrate the destructor.

Module Module1
    Class Sample
        Public Sub New()
            Console.WriteLine("Constructor called")
        End Sub

        Protected Overrides Sub Finalize()
            Console.WriteLine("Destructor called")
        End Sub
        Public Sub SayHello()
            Console.WriteLine("Hello World")
        End Sub
    End Class
    
    Sub Main()
        Dim obj As New Sample()
        obj.SayHello()
    End Sub
End Module

Output:

Constructor called
Hello World
Destructor called
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1. Here, we created a class Sample that contains a data member num. The Sample class contains a constructor and destructor.

Here, we implemented the destructor using the finalize() method.

The Main() method is the entry point for the program, here we created an object of Sample class and then called SayHello() method, it will print "Hello world" message on the console screen. Then destructor gets called automatically.

VB.Net Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.