public class Bank{ private List<Customer> customers; private int numberOfCustomers; public void Bank(){ customers=new ArrayList<Customer>(); } public void addCustomer(String f,String l){ customers.add(new Customer(f,l)); } public int getNumOfCustomers(){ numberOfCustomers=customers.size(); return numberOfCustomers; }
public static void main(String[] args) {
Bank cus=new Bank(){};
cus.addCustomer("Simms", "Jane"); //实例化时出现空指针异常
cus.addCustomer("Bryant", "Owen");
这是什么情况,求大神指教?
没看懂你这是什么语言 (add是小写?),c#的话构造函数不应该有void