I trying to understand the difference between the two lines below. Why is it returning a zero when I add static to the field.
private static final int this_year = Calendar.getInstance().get(Calendar.YEAR);
From this I get: this_year = 0;
private final int this_year = Calendar.getInstance().get(Calendar.YEAR);
And from this I get: this_year = 2013;
Someone who can explain why the first returns a zero?
Here's the code I use it in:
public class TheKing {
public static final TheKing theKing = new TheKing();
private final int beltSize;
private static final int this_year = Calendar.getInstance().get(Calendar.YEAR);
private TheKing() {
beltSize = this_year - 1930;
}
public int beltSize() {
return beltSize;
}
public static void main(String[] args) {
System.out.println("TheKing wears a size " +
theKing.beltSize() + " belt.");
}
}