package org.dothwinds.date;import java.util.Calendar;public class Student {
public static final Student STUDENT = new Student(); private final int age; private final static int Brithday = Calendar.getInstance().get(Calendar.YEAR); private Student() {
age = Brithday - 1983;
} public int MyAge() {
return age;
} public static void main(String[] args) {
System.out.println("The Student age is " + STUDENT.MyAge());
}
}最后答案The Student age is -1983
但是去掉static就是24(也就是想要的结果)
不明白为什么~~
请教了~
public static final Student STUDENT = new Student(); private final int age; private final static int Brithday = Calendar.getInstance().get(Calendar.YEAR); private Student() {
age = Brithday - 1983;
} public int MyAge() {
return age;
} public static void main(String[] args) {
System.out.println("The Student age is " + STUDENT.MyAge());
}
}最后答案The Student age is -1983
但是去掉static就是24(也就是想要的结果)
不明白为什么~~
请教了~
public static final Student STUDENT = new Student();
时,还没伦到
private final static int Brithday = Calendar.getInstance().get(Calendar.YEAR);
所以i为0,然后赋给final的age,所以age=0-1983