Consider the following program and predict the output:
import java.text.DateFormat; import java.util.*; class Main {/* ww w . j av a2s . c om*/ public static void main(String[] args) { DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.US); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, 2012); c.set(Calendar.MONTH, 12); c.set(Calendar.DAY_OF_MONTH, 1); System.out.println(df.format(c.getTime())); } }
d)
The month index starts from 0; thus, if you give the month an index of 12, it will increase the year by one and start counting from January.