Inherits Person

  

   Private student_number As Integer

   Public Overloads Sub SetValue( ByVal na As String, ByVal a As Integer, ByVal

                              no As Integer)

       SetValue(na, a)

       student_number = no

   End Sub

   Public Overrides Sub Display()

       MyBase.Display()

       Messagebox.Show("StudNo: " + str(student_number))

   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 x As New Person()

       x.SetValue("Alvin", 32)

       Dim y As New Student()

       y.SetValue("Tom", 36, 11138)

       x.Display()

       y.Display()

   End Sub

End Class

 

此程序输出﹕

            Name: Alvin    Age: 32

            Name: Tom      Age: 36

            StudNo: 11138

 

   此时﹐Student 类别含有两个SetValue()程序,一个是从Person类别继承而来,另一个是自行定义的。如果上述Form1_Click()内的指令更改如下:

 

 

       Dim y As New Student()

       y.SetValue("Tom", 36, 5000.25)   Error!

       y.Display()