Given that Calendar.MONTH starts with January == 0, and given:
import java.util.Calendar; public class Main { public static void main(String[] args) { Calendar c = Calendar.getInstance(); c.set(1999, 11, 25);// w w w. j a va 2 s . c om c.roll(Calendar.MONTH, 3); c.add(Calendar.DATE, 10); System.out.println(c.getTime()); } }
And, if the program compiles, what date is represented in the output?
B is correct.
It's important to remember that roll()
changes the Calendar field specified WITHOUT incrementing a date's bigger time chunks.
The add()
method changes the field's value AND also increments the bigger time chunks (like adding a new day or month), when appropriate.
Note that Calendar instances are created using a factory method.