当前位置:编程学习 > VB >>

VB.Net中文教程(1) 类别与封装性(5)

 

 

varity = v

       age = a

       height = hei

   End Sub

   Public Sub Show()

       MessageBox.Show(varity + ", " + str(age) + ", " + str(height))

   End Sub

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()

       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 a, b As New Tree()

       a.input("peach", 8, 2.1)

       b.input("pinapple", 2, 0.5)

       a.Show()

       b.Show()

   End Sub

End Class

 

   这个VB程序﹐Tree内之资料成员──variety, age及height皆为Private成员,而input()及Show()程序是Public成员。Form1_Click()程序中﹐首先诞生对象── a及 b。接下来﹐指令──

              

            

 

把 3项资料分别存入对象 a之资料成员中﹐a 之内容为﹕

 

    

       

同样地﹐指令──

              b.input( "pineapple", 2, 0.5 )

 

也把 3项资料存入对象 b之中﹐则 b之内容为﹕

 

      

  

最后﹐呼叫Show()程序把对象 a和对象 b之内容显示出来﹕

     

                peach,  8,  2.1

                pineapple,  2,  .5

 

补充:软件开发 , Vb ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,