Module Tester
Sub Main()
Dim circle1, circle2 As Circle
circle1 = New Circle(72, 29, 4.5) ' instantiate objects
circle2 = New Circle(5, 5, 10)
circle1 = Nothing ' mark objects for garbage collection
circle2 = Nothing
System.GC.Collect() ' request garbage collector to execute
End Sub ' Main
End Module
Public Class Point
Private mX, mY As Integer
Public Sub New()
Console.WriteLine("Point constructor: {0}", Me)
End Sub ' New
Public Sub New(ByVal xValue As Integer, _
ByVal yValue As Integer)
Console.WriteLine("Point constructor: {0}", Me)
End Sub ' New
Protected Overrides Sub Finalize()
Console.WriteLine("Point Finalizer: {0}", Me)
MyBase.Finalize() ' call Object finalizer
End Sub
' return String representation of Point
Public Overrides Function ToString() As String
Return "[" & mX & ", " & mY & "]"
End Function ' ToString
End Class
Public Class Circle
Inherits Point
Private mRadius As Double
Public Sub New()
Console.WriteLine("Circle constructor: {0}", Me)
End Sub ' New
Public Sub New(ByVal xValue As Integer, _
ByVal yValue As Integer, ByVal radiusValue As Double)
MyBase.New(xValue, yValue)
Console.WriteLine("Circle constructor: {0}", Me)
End Sub ' New
Protected Overrides Sub Finalize()
Console.WriteLine("Circle Finalizer: {0}", Me)
MyBase.Finalize() ' call Point finalizer
End Sub ' Finalize
Public Overrides Function ToString() As String
Return "Center = " & MyBase.ToString() & _
"; Radius = " & mRadius
End Function ' ToString
End Class
|