Question: JAVA Define a class variable in each sub class (SavingsAccount and CurrentAccount), which will keep a track of how many objects have been created from
JAVA
Define a class variable in each sub class (SavingsAccount and CurrentAccount), which will keep a track of how many objects have been created from that class.
public class SavingAccount extends Account { private double interestRate;
public SavingAccount(int accountNumber, double interestRate) { super(accountNumber); this.interestRate = interestRate; }
public void display() { super.display(); System.out.println("Interest rate: " + interestRate); } }
public class CurrentAccount extends Account { private double overdraftLimit;
public CurrentAccount(int accountNumber, double overdraftLimit) { super(accountNumber); this.overdraftLimit = overdraftLimit; }
public void withdraw(double amount) { if (amount > 0) if ((balance + overdraftLimit) - amount >= 0) balance -= amount; else System.err.println("Account.withdraw(...): " + "cannot withdraw more than your balance."); else System.err.println("Account.withdraw(...): " + "cannot withdraw negative amount."); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
