由於構造函數的問題,我編譯代碼時出現錯誤。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 –