Question
Identify the output of following Java code. Write in between Java comments to justify the syntax. /** The BankAccount class simulates a bank account. */
- Identify the output of following Java code. Write in between Java comments to justify the syntax.
/**
The BankAccount class simulates a bank account.
*/
public class BankAccount
{
private double balance; // Account balance
public BankAccount()
{
balance = 0.0;
}
public BankAccount(double startBalance)
{
balance = startBalance;
}
public BankAccount(String str)
{
balance = Double.parseDouble(str);
}
public void deposit(double amount)
{
balance += amount;
}
public void deposit(String str)
{
balance += Double.parseDouble(str);
}
public void withdraw(double amount)
{
balance -= amount;
}
public void withdraw(String str)
{
balance -= Double.parseDouble(str);
}
public void setBalance(double b)
{
balance = b;
}
public void setBalance(String str)
{
balance = Double.parseDouble(str);
}
public double getBalance()
{
return balance;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started