日期:2014-05-20  浏览次数:20709 次

一道想不通的题
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 static int Brithday = Calendar.getInstance().get(Calendar.YEAR);
所以i为0,然后赋给final的age,所以age=0-1983