这只是我代码的一部分。我有这个名为Account的抽象超类,我想在Subclass的方法中访问ArrayList:
public abstract class Account {
private String accountNumber;
private ArrayList<String> accountRecords;
public Account() {
super();
accountRecords = new ArrayList<String>();
}
public String getAccountNumber() {
return accountNumber;
}
public abstract void addTransaction(String transactionInfo);
}
public class SubAccount extends Account {
public SubAccount() {
super();
}
public void addTransaction(String transaction) {
if (super.getAccountNumber() != null &&
!super.getAccountNumber().isEmpty()) {
accountRecords.add(transaction); //How can I access the
ArrayList here?
}
}
}
答案 0 :(得分:0)
为超类中的arraylist编写一个getter并调用super.getArrayList()
答案 1 :(得分:0)
将accountRecords
的访问权限更改为protected
:
protected ArrayList<String> accountRecords;