这里是我的超类问题得到构造继承正确
public class BankAccount
{
double balance;
public BankAccount(double initialBalance)
{
this.balance = initialBalance;
}
public void deposit(double amount)
{
balance += amount;
}
public void withdraw(double amount)
{
balance -= amount;
}
public double getBalance()
{
return balance;
}
public void transfer(double amount, BankAccount other)
{
balance -= amount;
}
}
下面是扩展类是
public class CheckingAccount extends BankAccount
{
int transactionCount;
double fee;
public CheckingAccount(double initialBalance)
{
this.balance = initialBalance;
this.transactionCount = 0;
}
public void deposit(double amount)
{
balance += amount;
transactionCount += 1;
}
public void withdraw(double amount)
{
balance -= amount;
transactionCount += 1;
}
public void deductFees()
{
if(transactionCount > 3)
{
fee = 2.0*(transactionCount-3);
}
balance -= fee;
transactionCount = 0;
}
}
构造工作正常的超类,但是当我尝试以扩展类我得到的错误,构造函数不能应用于给定的类型,即使我正在申请一个双重的,就像它是在超类。我刚开始学习继承类,所以任何输入是非常赞赏
调用'super(whatever) '在你的子类的构造函数的顶部。 – khelwood 2014-09-20 17:24:33