Some programmers like to use the this
variable with instance variables and method calls on the implicit parameter object. Rearrange the code of the BankAccount
class
below that makes use of the this
variable. (The withdraw
and getBalance
methods are omitted.)
Not all lines are useful.
^public class BankAccount +{ + private double balance; + public BankAccount() + { . this.balance = 0; ^ } + public BankAccount(double balance) + { . this.balance = balance; - balance = this.balance; ^ } + public void deposit(double amount) + { . this.balance = this.balance + amount; ^ } + public void transfer(double amount, BankAccount to) + { . this.withdraw(amount); , to.deposit(amount); - this.to.deposit(amount); - to.deposit(this.amount); ^ } + // ... +}