This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Assuming calendarOne and calendarTwo have different years, why does each line return a different number?--I thought all objects of a class share the static variables of a class, so doesn't that mean CalendarOne and CalendarTwo would share the same Calendar.YEAR, since YEAR is static? But it seems like they don't b/c each Calendar.YEAR is returning a different year. How it that possible?
It works like this: Class Calendar has a get() method. You can use this to get different values that are set in the calendar object - for example the year, month or day that the calendar is set to. You pass a constant such as Calendar.YEAR to the get() method to tell it which value to return.
So if you call calendarOne.get(Calendar.YEAR), then the get() method sees "aha, he wants me to return the year that this calendar is set to".
Calendar.YEAR is a constant, but each calendar object can ofcourse be set to a different date. You're confusing the meaning of Calendar.YEAR and the current date setting of the calendar object.
Calender.YEAR,Calender.MONTH etc.. can be considered as constants which identifies the property you are trying to get. So to identify each properties we can use these constants as provided. But each instance has it's own values as you set them and Calender.YEAR means same property in each instance (say year etc).