你好我有一個覆蓋存款方法的問題。我有一個BankAccount類(主要的),InterestAccount(擴展了BankAccount)和IsaAccount(擴展了InterestAccount)。我無法撥打餘額以添加IsaAccount類的存款方式中提到的金額。我已經嘗試了很多使用getBalance,super(balance),super.getBalance等的方法。這耗盡了我很多......我瀏覽了許多類似的話題,但找不到解決這個特定問題的辦法。我必須做一個存款方法,這樣我才能把錢存入IsaAccount對象。不能從超級,超級類別「訪問」變量
public class BankAccount {
private int balance;
public BankAccount() {
balance = 0;
}
......................
public class InterestAccount extends BankAccount {
private int interestRate;
private int minimumBalance;
public InterestAccount() {
super();
interestRate = 0;
minimumBalance = 100;
}
......................
public class IsaAccount extends InterestAccount {
private int depositRemaining;
public IsaAccount() {
super();
depositRemaining = 0;
}
public IsaAccount(int balance, int interestRate, int minimumBalance, int depositRemaining) {
super(balance, interestRate, minimumBalance);
this.depositRemaining = depositRemaining;
}
@Override
public void deposit(int amount) {
if (amount <= depositRemaining)
<HERE I NEED TO CALL BALANCE(not sure whether I have to use get
methods or what) e.g balance = balance + amount; >
}
......................
看來你嘗試*控*有沒有一種方法已在父母中定義。你也調用不存在的父構造函數。 –
你應該包括完整的BankAccount類定義 – Typo
流行測驗:「私人」是什麼意思/做什麼? – immibis