| Imports System Namespace MyNamespace |
| Class Payroll Overridable Function PayEmployee(ByVal HoursWorked As Single, ByVal PayRate As Single) PayEmployee = HoursWorked * PayRate End Function End Class |
| Class BonusPayroll Inherits Payroll Overrides Function PayEmployee(ByVal HoursWorked As Single, ByVal PayRate As Single) PayEmployee = (HoursWorked * PayRate) * 1.45 @# 45% 紅利 End Function End Class |
| Module MyModule Sub Main() Dim BonusPayrollItem As Bonuspayroll = New Bonuspayroll Dim PayrollItem As Payroll = New Payroll Dim PayRate As Single = 14.75 Dim HoursWorked As Single = 40 Console.WriteLine("Normal pay is: " & Pay(PayrollItem, HoursWorked, PayRate)) Console.WriteLine("Pay with bonus is: " & Pay(BonusPayrollItem, HoursWorked, PayRate)) End Sub |
| Function Pay(ByVal PayObject As Payroll, ByVal HoursWorked As Single, ByVal PayRate As Single) Pay = PayObject.PayEmployee(HoursWorked, PayRate) * 0.75 @# withold tax End Function End Module End Namespace |
【