package day01;
public class Employee {
public Employee(String n,int i){
String name = n;
int id = i;
}
private static int id;
public static void setId(){
id++;
}
public static void main(String args[]){
Employees[] ee =new Employees[3];
ee[0] = new Employees("张三",1000);
ee[1] = new Employees("李四",2000);
ee[2] = new Employees("王五",1800);
for(int i = 0;i<ee.length;i++){
setId();
System.out.println("名字" + ee[i].getName() +" ID=" + ee[i].getId());
}
}
}
运行结果是
名字张三 ID=null
名字李四 ID=null
名字王五 ID=null
怎么不是
名字张三 ID=1801
名字李四 ID=1802
名字王五 ID=1803
|