public class Demo03StaticStudent {
public static void main(String[] args) {
Student.room="101教室";
Student one=new Student("郭靖",20);
System.out.println("one的姓名:"+one.getName());
System.out.println("one的年龄:"+one.getAge());
System.out.println("one的教室:"+Student.room);
System.out.println("=============");
Student two=new Student("黄蓉",18);
System.out.println("two的姓名:"+two.getName());
System.out.println("two的年龄:"+two.getAge());
System.out.println("two的教室:"+Student.room);
}
}
public class Student {
private int id;
private String name;
private int age;
static String room;
private static int idCounter=0;
public Student() {
idCounter++;
}
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;
}
}