构造方法和类名不一致,修改如下:
public class Students {
int id = 0;
static int studentNum = 0;
Students(int a) {
id = a;
studentNum++;
}
public static void main(String[] args) {
Students s1 = new Students(1);
Students s2 = new Students(2);
Students s3 = new Students(3);
Students s4 = new Students(4);
System.out.println(s1.id);
System.out.println(s2.id);
System.out.println(s3.id);
System.out.println(s4.id);
System.out.println(Students.studentNum);
}
}