VB.Net中文教程(2) 继承与封装性(4)

页面导航:首页 > 软件编程 > vb.net > VB.Net中文教程(2) 继承与封装性(4)

VB.Net中文教程(2) 继承与封装性(4)

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

Public Sub New() MyBase.New() Form1 = Me This

 

 

   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 p1 As New FullTime_Teacher("David", 25)

       p1.Show()

       p1.modifyValue("Kent Smith", 45)

       p1.Show()

   End Sub

End Class

 

此程序输出:

             Name: David         Age: 25

             Name: Kent Smith    Age: 45

 

 

   Show()是Person类别的Public程序,孙子类别FullTime_Teacher继承之,成为FullTime_Teacher类别的Public程序,所以Form1_Click()程序能写着指令:p1.Show()。name和modifyAge()是Person的Protected成员,Teacher的modify()程序里能直接使用它们。而且FullTime_Teacher的modifyData()程序里能直接使用它们。但是Form1_Click()就无法使用它们。modify()是Teacher的Protected成员,FullTime_Teacher的modifyValue()程序里能直接使用它们,但Form1_Click()就不行使用。所以若将上述Form1_Click()的指令改为如下,就不对了:

 

Protected Sub Form1_Click( ..... )

       Dim p1 As New FullTime_Teacher("David", 25)

       p1.Show()

       p1.modify("Kent Smith", 45)   Error!

       p1.modifyAge(24)   Error!

       p1.Show()

   End SubEnd Class

 

 

Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<