My code does not compile. How can I resolve the errors?
import java.util.*; public class BankAccount{ private double balance; public BankAccount(double b) { balance = b; } public double getBalance(){ return balance; } public void deposit(double d){ balance += d; } public boolean withdraw(double d){ if(d > balance){ return false; } else { balance -= d; return true; } } public class SavingsAccount extends BankAccount{ private double interest; public SavingsAccount(double k, double inRate){ super(k); interest = inRate; } public void gainInterest(){ super.getBalance() = super.getBalance() * interest; } } public static void main(String[] args) { SavingsAccount test = new SavingsAccount(1000, .05); test.gainInterest(); System.out.println(test.getBalance()); } The following errors are
I get the unexpected type error at super.getBalance() = super.getBalance() * interest; and the "non-static variable this cannot be referenced from a static context" at SavingsAccount test = new SavingsAccount(1000, .05);
super.getBalance() = ...does?