I'm a beginning programmer trying to learn the basics of java. Basically, the methods printBankSummary() and accrueInterestAllAccounts() in the bank class are giving me this problem. Here are the codes:
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(); }
BankAccount.printAccountInfo();andSavingsAccount.accrueInterest();Both lines are in the Bank class.