VB.Net中文教程(3)程序多重定义(4)

页面导航:首页 > 软件编程 > vb.net > VB.Net中文教程(3)程序多重定义(4)

VB.Net中文教程(3)程序多重定义(4)

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

Else MessageBox.Show("NOT EQUAL") End If End SubEnd Cla

 

 

Else

           MessageBox.Show("NOT EQUAL")

       End If

   End Sub

End Class

 

此程序输出﹕

NOT EQUAL

EQUAL

EQUAL

 

由于各程序名称不相同,您就得记忆各程序之名字﹐徒增记忆负担而且易于犯错﹐并不合乎人们生活习惯。因之﹐VB的多重定义观念﹐能增加程序之弹性及亲切感。

   程序多重定义情形并不限于单一类别之内,也可以发生于父子类别之间。例如:

 

ex06.bas

Imports System.ComponentModel

Imports System.Drawing

Imports System.WinForms

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

Public Class Person

   Private name As String

   Private age As Integer

   Public Sub New()

   End Sub

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

       name = na

       age = a

   End Sub

   Public Function birthDay() As Integer

       birthDay = 2001 - age

   End Function

   Public Sub Display()

       Messagebox.Show("Name: " + name + "   Age: " + str(age))

   End Sub

End Class

 

Public Class Teacher

   Inherits Person

  

   Private salary As Decimal

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

                              sa As Decimal)

       SetValue(na, a)

       salary = sa

   End Sub

   Public Sub pr()

Tags:

文章评论


<