我看过示例,它们的类,类变量或构造函数都不包含静态变量;但是他们仍然能够使用构造函数创建对象。我的代码每次都会出现错误:
错误:非静态变量,不能从静态上下文中引用 客户ID_1 =新客户(“丹尼尔”,0123123412); public class ProjectTBD {
private class Customer {
String name;
int accountNumber;
//Constructor
private Customer(String customerName, int customerNumber) {
name = customerName;
accountNumber = customerNumber;
}
}
public static void main(String[] args) {
Customer id_1 = new Customer("Daniel", 0123123412);
System.out.println(id_1.name);
}
}