VB.Net中文教程(4) 母子对象关系(4)

页面导航:首页 > 软件编程 > vb.net > VB.Net中文教程(4) 母子对象关系(4)

VB.Net中文教程(4) 母子对象关系(4)

来源: 作者: 时间:2016-02-05 12:32 【

public Overrides Sub Dispose() MyBase.Dispose() components.Dispose() End Sub&nb

 

 

public Overrides Sub Dispose()

       MyBase.Dispose()

       components.Dispose()

   End Sub

  

#Region " Windows Form Designer generated code "

    ......

#End Region

   Protected Sub Form1_Click(ByVal sender As Object,

                           ByVal e As System.EventArgs)

       Dim r As New MyRoom()

       r.Show()

   End Sub

End Class

 

此程序输出:

              Room Size: 100

              Desk Size:  18

 

3. 特类别继承与母子对象

 

   您已很熟悉父子类别关系了﹐这继承关系的另一面是母子对象关系。例如﹐

 

ex06.bas

Imports System.ComponentModel

Imports System.Drawing

Imports System.WinForms

----------------------------------------------------

Class Room

   Private mother As MyRoom

  

   Public Sub New(ByVal mo As MyRoom)

       mother = mo

   End Sub

   Public Function GetID() As String

       GetID = mother.yourID()

   End Function

End Class

 

Class MyRoom

   Inherits Room

  

   Public Sub New()

       MyBase.New(Me)

   End Sub

   Public Function yourID() As String

       yourID = "VIP888"

   End Function

End Class

----------------------------------------------------

Public Class Form1

   Inherits System.WinForms.Form

  

   Public Sub New()

       MyBase.New()

       Form1 = Me

       This call is required by the Win Form Designer.

       InitializeComponent()

       TODO: Add any initialization after the InitializeComponent() call

   End Sub

   Form overrides dispose to clean up the component list.

   Public Overrides Sub Dispose()

       MyBase.Dispose()

      

Tags:

文章评论


<