Search This Blog

Tuesday, January 5, 2010

Abstract Class Implementation in VB.Net

Public MustInherit Class Accounts
Private name As String
Protected balance As Double
Public Sub New(ByVal n As String, ByVal b As Double)
name = n
balance = b
End Sub
Public Overridable Sub credit(ByVal amount As Double)
balance += amount
End Sub
Public Overridable Sub debit(ByVal amount As Double)
balance -= amount
End Sub
Public Overridable Sub display()
MsgBox("Name =" & name & ", Balance =" & balance)
End Sub
Public MustOverride Function calculatebankcharge() As Double

End Class

Public Class SavingAccounts
Inherits Accounts
Private minbalance As Double
Public Sub New(ByVal n As String, ByVal b As Double, ByVal min As Double)
MyBase.new(n, b)
minbalance = min
End Sub
Public Overrides Sub debit(ByVal amount As Double)
If amount <= Balance Then
MyBase.debit(amount)
End If

End Sub

Public Overrides Sub display()
MyBase.display()
MsgBox("$5 charge if balance goes below $" & minbalance)
End Sub
Public Overrides Function calculatebankcharge() As Double
If Balance < minbalance Then
Return 5.0
Else
Return 0.0
End If

End Function
End Class