我是一名初级程序员,试图学习 Java 的基础知识。基本上,银行类中的方法 printBankSummary() 和 accrueInterestAllAccounts() 给了我这个问题。以下是代码:
public class Bank {
private String name;
private SavingsAccount [] accounts;
private int totalAccounts;
public static final int MAX_ACCOUNTS = 20;
public Bank(String name) {
this.name = name;
totalAccounts = 0;
accounts = new SavingsAccount[MAX_ACCOUNTS];
}
public void printBankSummary() {
System.out.println("Bank name: " + getName());
BankAccount.printAccountInfo(); //non-static method cannot be referenced from a static context error
}
public void accrueInterestAllAccounts() {
SavingsAccount.accrueInterest(); //non-static method cannot be referenced from a static context error
}
public static void main (String args[]) {
Bank x = new BankAccount("Java S&L");
x.printBankSummary();
x.accrueInterestAllAccounts();
}