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

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

 

 

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

补充:软件开发 , Vb ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,