Write a program to demonstrate Constructors and Destructors in VB.net.

Write a program to demonstrate Constructors and Destructors in VB.net.

WAP to Demonstrate Constructors and Destructors in VB.net.

Imports System.Console

Module Module1

Class base

Private a As Integer

Private b As Double

Private c As String

 

Public Sub New(ByVal x As Integer, ByVal y As Double, ByVal z As String)

WriteLine("Constructor Of Base Class Executed ! ")

a = x

b = y

c = z

WriteLine("a=" & a)

WriteLine("b=" & b)

WriteLine("c=" & c)

End Sub

 

Protected Overrides Sub finalize()

WriteLine("Destructor of Base Class Executed ! ")

End Sub

End Class

 

Class derive : Inherits base

Private d As Integer

Public Sub New(ByVal e As Integer, ByVal x As Integer, ByVal y As Double, ByVal z As String)

MyBase.New(x, y, z)

WriteLine("Constructor of Derived Class Executed!")

d = e

WriteLine("d=" & d)

End Sub

Protected Overrides Sub finalize()

WriteLine("Destructor of Derived Class Executed ! ")

End Sub

End Class

 

Sub Main()

WriteLine("When WE Declare Object of Base Classs :- ")

WriteLine()

WriteLine()

Dim s1 As base = New base(20, 30.5, "GOGO")

 

WriteLine("When WE Declare Object of Derived Classs :- ")

WriteLine()

WriteLine()

Dim s2 As derive = New derive(10, 20, 30.5, "GOGO")

 

End Sub

 

End Module

OUTPUT

. WAP to Demonstrate Constructors and Destructors in VB.net.

0 Like

Leave a Reply

Your email address will not be published. Required fields are marked *
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>