Java Reference
In-Depth Information
and
BankAccount b = new BankAccount(5000);
΢ Exercise R3.4 What happens in our implementation of the BankAccount
class when more money is withdrawn from the account than the current
balance?
΢ Exercise R3.5 What is the value of b.getBalance() after the
following operations?
BankAccount b = new BankAccount(10);
b.deposit(5000);
b.withdraw(b.getBalance() / 2);
΢΢Exercise R3.6 If b1 and b2 refer to objects of class BankAccount ,
consider the following instructions.
b1.deposit(b2.getBalance());
b2.deposit(b1.getBalance());
Are the balances of b1 and b2 now identical? Explain.
΢΢Exercise R3.7 What is the this reference? Why would you use it?
΢΢Exercise R3.8 What does the following method do? Give an example of
how you can call the method.
public class BankAccount
{
public void mystery(BankAccount that,
double amount)
{
this.balance = this.balance - amount;
that.balance = that.balance + amount;
}
. . . // Other bank account methods
}
124
125
΢΢Exercise R3.9 Suppose you want to implement a class
SavingsAccount . A savings account has deposit , withdraw , and
getBalance methods like a bank account, but it has a fixed interest rate
that should be set in the constructor, together with the initial balance. An
Search WWH ::




Custom Search