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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!