Imports System
Public Class MainClass
Shared Sub Main()
Dim tom As New Employee("Tom", 50000, "111-11-1234")
Dim sally As New Employee("Sally", 150000, "111-11-2234")
Dim ourEmployees(1) As PayableEntity
ourEmployees(0) = tom
ourEmployees(1) = sally
Dim anEmployee As PayableEntity
For Each anEmployee In ourEmployees
Console.WriteLine(anEmployee.TheName & " has tax id " & anEmployee.TaxID )
Next
End Sub
End Class
Public MustInherit Class PayableEntity
Private m_Name As String
Public Sub New(ByVal itsName As String)
m_Name = itsName
End Sub
ReadOnly Property TheName() As String
Get
Return m_Name
End Get
End Property
Public MustOverride Property TaxID() As String
End Class
Public Class Employee
Inherits PayableEntity
Private m_Salary As Decimal
Private m_TaxID As String
Private Const LIMIT As Decimal = 0.1D
Public Sub New(ByVal theName As String, ByVal curSalary As Decimal, ByVal TaxID As String)
MyBase.New(theName)
m_Salary = curSalary
m_TaxID = TaxID
End Sub
Public Overrides Property TaxID() As String
Get
Return m_TaxID
End Get
Set(ByVal Value As String)
m_TaxID = Value
End Set
End Property
ReadOnly Property Salary() As Decimal
Get
Return MyClass.m_Salary
End Get
End Property
Public Overridable Overloads Sub RaiseSalary(ByVal Percent As Decimal)
If Percent > LIMIT Then
'not allowed
Console.WriteLine("Percent > LIMIT")
Else
m_Salary = (1D + Percent) * m_Salary
End If
End Sub
Public Overridable Overloads Sub RaiseSalary(ByVal Percent As _
Decimal, ByVal Password As String)
If Password = "special" Then
m_Salary = (1D + Percent) * m_Salary
End If
End Sub
End Class
|