Question: Consider the following class, which uses the instance variable balance to represent a bank account balance. public class BankAccount { private double balance; public double
Consider the following class, which uses the instance variable balance to represent a bank account balance.
public class BankAccount { private double balance; public double deposit(double amount) { /* missing code */ } } The deposit method is intended to increase the account balance by the deposit amount and then return the updated balance. Which of the following code segments should replace /* missing code */ so that the deposit method will work as intended?
-
amount = balance + amount;
return amount;
-
balance = amount;
return amount;
-
balance = amount;
return balance;
balance = amount;, , return balance;,
-
balance = balance + amount;
return amount;
balance = balance + amount;
-
return balance;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
