Java Reference
In-Depth Information
// Now add amount to balance
super. deposit(amount);
}
. . .
}
This version of the deposit method is correct. To deposit money into a checking
account, update the transaction count and call the deposit method of the superclass.
The remaining methods are now straightforward.
public class CheckingAccount extends BankAccount
{
. . .
public void withdraw(double amount)
{
transactionCount++;
// Now subtract amount from balance
super. withdraw(amount);
}
public void deductFees()
{
if (transactionCount > FREE_TRANSACTIONS)
{
double fees = TRANSACTION_FEE
* (transactionCount -
FREE_TRANSACTIONS);
super. withdraw(fees);
}
transactionCount = 0;
}
. . .
private static final int FREE_TRANSACTIONS = 3;
private static final double TRANSACTION_FEE = 2.0;
}
448
449
S YNTAX 10.2 Calling a Superclass Method
super. methodName(parameters);
Example:
public void deposit(double amount)
{
Search WWH ::




Custom Search