Java - Utility Classes - Interview Questions and Answers on Calendar

Q1.  Will this code Work ?  If not , Why ?

java.util.Calendar c = new java.util.Calendar();

Ans. No. It gives the error "Cannot Instantiate the type Calendar". Calendar is an abstract class and hence Calendar object should be instantiated using Calendar.getInstance().

Q2.  Is java.util.Date an abstract Class ? Is java.util.Calendar an abstract Class ?

Ans. Date is not a abstract class whereas Calendar is.

Q3.  What will the following code print ?

java.util.Calendar c = java.util.Calendar.getInstance();
c.add(Calendar.MONTH, 5);
System.out.println(c.getTime());

Ans. Date and Time after 5 months from now.