Page 174 - AP Computer Science A, 7th edition
P. 174

if (b1.getBalance() > b2.getBalance()) better = b1;
else
better = b2;
return better; }
public static void main(String[] args) {
BankAccount briansFund = new BankAccount("BrianL", 10000);
BankAccount paulsFund = new BankAccount("PaulM", 90000);
BankAccount betterFund = chooseBestAccount(briansFund, paulsFund);
...
}
NOTE
The effect of this is to create the betterFund reference, which
refers to the same object as paulsFund:
What the method does not do is create a new object to which betterFund refers. To do that would require the keyword new and use of a BankAccount constructor. Assuming that a getPassword() accessor has been added to the BankAccount class, the code would look like this:
 




















































































   172   173   174   175   176