摘要:(200-06-21) VB.NET 類別規劃 建構子 Constructr
建構子(Constructr) : :建構子沒有繼承
沒有寫編譯產生預設建構子(空參數)
自己寫->不會產生預設建構子
物件建構同時初始化
'自訂建構子(參數)
Public Sub New(ByVal _id As String, ByVal _name As String, ByVal _brithDate As DateTime, ByVal _sex As String)
'隱含編譯指向父親空參數
Me._id = _id
Me._name = _name
Me._sex = _sex
If (_brithDate <= DateTime.Now) Then
Me._birthDate = _brithDate
End If
End Sub
'建構子OverLoading
Public Sub New()
'隱含編譯指向父親空參數
End Sub
指定父親建構子 MyBase.New( ::需在第一行
Public Sub New()
'隱含編譯一行指向父親空參數
MyBase.New("", "", "2000/1/1", "")
System.Console.WriteLine("業務員建構!!")
End Sub
'參數
Public Sub New(ByVal _id As String, ByVal _name As String, ByVal _birthDate As DateTime, ByVal _sex As String, ByVal _qa As Decimal)
'部分父親建構
MyBase.New(_id, _name, _birthDate, _sex)
Me._qa = _qa
End Sub