VB.Net Program to Demonstrate the Destructor

You are currently viewing VB.Net Program to Demonstrate the Destructor

VB.Net program to demonstrate the destructor

'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 . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply