Java Reference
In-Depth Information
21 deposit(interest);
22 }
23
24 private double interestRate;
25 }
Output
Mom's savings balance: 7035.0
Expected: 7035
Harry's checking balance: 1116.0
Expected: 1116
459
460
S ELF C HECK
12. If a is a variable of type BankAccount that holds a non -null
reference, what do you know about the object to which a refers?
13. If a refers to a checking account, what is the effect of calling
a.transfer(1000, a) ?
A DVANCED T OPIC 10.1: Abstract Classes
When you extend an existing class, you have the choice whether or not to redefine
the methods of the superclass. Sometimes, it is desirable to force programmers to
redefine a method. That happens when there is no good default for the superclass,
and only the subclass programmer can know how to implement the method
properly.
Here is an example. Suppose the First National Bank of Java decides that every
account type must have some monthly fees. Therefore, a deductFees method
should be added to the BankAccount class:
public class BankAccount
{
public void deductFees() { . . . }
. . .
}
But what should this method do? Of course, we could have the method do nothing.
But then a programmer implementing a new subclass might simply forget to
Search WWH ::




Custom Search