SCJP Module-12 Question-6


 

SCJP Module-12 Question-6

The Sample code given below will test your understanding about the Date, DateFormate classes in Java and will also check how the formate the Date in Java.

The Sample code given below will test your understanding about the Date, DateFormate classes in Java and will also check how the formate the Date in Java.

Given below the sample code :

1. Date dt = new Date();
2. String ds = ?December 21, 2009″;
3. // insert code here
4. try {
5. dt = datef.parse(ds);
6. }
7. catch(ParseException pe) {
8. System.out.println(?Unable to parse ? + ds);
9. }
10. // insert code here

Which code lines should add at line number 3 and 10 to add a day to the Date object?

1. 3.   DateFormat datef = DateFormat.getDateFormat();
    10. dt.setTime( (60 * 60 * 24) + dt.getTime());
2. 3.   DateFormat datef = DateFormat.getDateInstance();
    10. dt.setTime( (1000 * 60 * 60 * 24) + dt.getTime());
3. 3.   DateFormat datef = DateFormat.getDateFormat();
    10. dt.setLocalTime( (1000*60*60*24) + dt.getLocalTime());
4. 3.   DateFormat datef = DateFormat.getDateInstance();
    10. dt.setLocalTime( (60 * 60 * 24) + dt.getLocalTime());

Answer

(2)

 


Ads