Display order in which base-class and derived-class constructors and finalizers are called : Finalize « Development « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Development » Finalize 
7.11.2.Display order in which base-class and derived-class constructors and finalizers are called
Module Tester

   Sub Main()
      Dim circle1, circle2 As Circle

      circle1 = New Circle(72294.5' instantiate objects
      circle2 = New Circle(5510)

      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
Point constructor: Center = [0, 0]; Radius = 0
Circle constructor: Center = [0, 0]; Radius = 0
Point constructor: Center = [0, 0]; Radius = 0
Circle constructor: Center = [0, 0]; Radius = 0
Circle Finalizer: Center = [0, 0]; Radius = 0
Point Finalizer: Center = [0, 0]; Radius = 0
Circle Finalizer: Center = [0, 0]; Radius = 0
Point Finalizer: Center = [0, 0]; Radius = 0
7.11.Finalize
7.11.1.Override Finalize method
7.11.2.Display order in which base-class and derived-class constructors and finalizers are called
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.