This is just part of my code. I have this Abstract Superclass called Account, and I want to access the ArrayList in a Subclass's method:
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?
}
}
}
为超类中的arraylist编写一个getter并调用super.getArrayList()
将accountRecords
的访问权限更改为protected
:
protected ArrayList<String> accountRecords;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.