isn't if there is a method in a subclass with the exact same signature, the subclass one is suppose to be called over the super?
Account
public class Account
{
//Declaring instance variables.
private int accountNumber;
private String ownersName;
private double interestRate;
protected double balance;
public Account(int aNum, String oName, double iRate, double bal)
{
//User initializing the instance variables.
accountNumber = aNum;
ownersName = oName;
interestRate = iRate;
if(bal < 0.0)
{
balance = 0.0;
}
else
{
balance = bal;
}
}
public void withdraw(double amt)
{
System.out.println("HUH?");
if(amt > 0.0)
{
balance = balance - amt;
}
else
{
balance = balance;
}
}
SavingsAccount
public class SavingsAccount extends Account
{
//Initiazling variables.
private int countWithdrawals;
public SavingsAccount(int aNum, String oName, double iRate, double bal)
{
//Declaring variables and calling superclass constructor.
super(aNum, oName, iRate, bal);
countWithdrawals = 0;
}
//Withdraws specified amount and penalties, if any, and increments the cout total.
public void withdraw(int number, double amt)
{
countWithdrawals++;
System.out.println("boo");
balance = balance - amt;
if(countWithdrawals > 3)
{
balance = balance - 30.0;
}
if(balance < 0.0)
{
balance = balance - 35.0;
}
}
//The addition to the super's toString() in Account.
public String toString()
{
return "Savings Account\n" + super.toString() + "\nWithdrawals Made: " + countWithdrawals;
}
}

New Topic/Question
Reply




MultiQuote




|