由于构造函数的问题,我编译代码时出现错误。Java - 继承与构造函数错误
这里是我的父类的构造函数:
public BankAccount(final String theNameOfOwner, final double theInterestRate)
{
myName = theNameOfOwner;
myInterestRate = theInterestRate;
myBalance = 0;
myMonthlyWithdrawCount = 0;
myMonthlyServiceCharges = 0;
}
这里是我的子类的构造函数:
public SavingsAccount(final String theNameOfOwner, final double theInterestRate)
{
BankAccount(theNameOfOwner, theInterestRate);
myStatusIsActive = false;
myWithdrawalCounter = 0;
}
我收到以下错误:
SavingsAccount.java:7: error: constructor BankAccount in class BankAccount cannot be applied to given types;
{
^
required: String,double
found: no arguments
reason: actual and formal argument lists differ in length
错误说我需要String,在我的子构造函数的BankAccount调用中的双参数,如果我正确理解这一点。唯一的问题是它看起来像我有这些参数是正确的。任何帮助/输入将不胜感激,因为我刚开始编程Java!谢谢!
尝试的超代替父类的名称 – Renjith
https://开头docs.oracle.com/javase/tutorial/java/IandI/super.html –