public class Student {
private int id;
private String name;
private int age;
static String room;
private static int idCounter=0;
public Student() {
}
public Student(String name, int age) {
this.name = name;
this.age = age;
this.id=++idCounter;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
public class Demo01staticfield {
public static void main(String[] args) {
Student student1=new Student("李华",18);
student1.room="101";
System.out.println("姓名"+student1.getName()+"年龄"+student1.getAge()+"教室"+student1.room+"学号"+student1.getId());
Student student2=new Student("李雷",19);
System.out.println("姓名"+student2.getName()+"年龄"+student2.getAge()+"教室"+student2.room+"学号"+student2.getId());
}
}