?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
Private Name As String ' Only accessible in base class
Protected Balance As Double ' Accessible in base class and derived class
Add a constructor to initialize these fields:
Public Sub New(ByVal Nm As String, ByVal Bal As Double)
Name = Nm
Balance = Bal
End Sub
Add the following methods to the class. TheOverridablekeyword means these methods can be overridden in derived classes:
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()
Console.WriteLine("Name=" & Name & ", " & "Balance=" & Balance)
End Sub
Add the following method to the class. Because this method is not marked asOverridable, it cannot be overridden in derived classes. This method provides the capability to change the name of the account holder.
Public Sub ChangeName(ByVal newName As String)
Name = newName
End Sub
Add the following method to the class. TheMustOverridekeyword means this method must be overridden in derived classes:
Public MustOverride Function CalculateBankCharge() As Double
Visual Studio .NET displays the file SavingsAccount.vb.
Change the SavingsAccount class definition as follows, so that SavingsAccount inherits from Account (note that theInheritskeyword must appear on a new line):
Public Class SavingsAccount
Inherits Account
End Class
Public Sub New(ByVal Nm As String, _
ByVal Bal As Double, _
ByVal Min As Double)
MyBase.New(Nm, Bal) ' Call base-class constructor first
MinBalance = Min ' Then initialize fields in this class
End Sub
Public Overrides Sub Debit(Amount As Double)
If Amount <= Balance Then ' Use balance, inherited from base class
MyBase.Debit(Amount) ' Call Debit, inherited from base class
End If
End Sub
Public Overrides Sub Display()
MyBase.Display() ' Call Display, inherited from base class
Console.WriteLine("$5 charge if balance goes below $" & MinBalance)
End Sub