我正在從另一個類繼承的類,但我得到一個編譯器錯誤說:「找不到符號構造函數Account()」。基本上我想要做的是創建一個從賬戶賬戶延伸的InvestmentAccount類,旨在與提取/存款的方法保持平衡,InvestmentAccount類似,但餘額存儲在股票中,股票價格決定了如何許多股票是以特定金額存入或提取的。以下是前幾行(約編譯器在其中指出的問題)子類InvestmentAccount的:繼承在Java中 - 「無法找到符號構造函數」
public class InvestmentAccount extends Account
{
protected int sharePrice;
protected int numShares;
private Person customer;
public InvestmentAccount(Person customer, int sharePrice)
{
this.customer = customer;
sharePrice = sharePrice;
}
// etc...
而Person類是在另一個文件(Person.java)舉行。現在,這裏的超類賬戶的第幾行:
public class Account
{
private Person customer;
protected int balanceInPence;
public Account(Person customer)
{
this.customer = customer;
balanceInPence = 0;
}
// etc...
沒有任何理由爲什麼編譯器不只是從Account類閱讀的符號構造的帳戶?還是我需要爲InvestmentAccount中的Account定義一個新的構造函數,它告訴它繼承一切?
感謝
正如我規則,我總是把super()調用放在我的構造函數中,當適用時。 – eljenso 2009-02-04 10:41:56