File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes The Calendar abstract Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "The Calendar abstract Class" Watch "The Calendar abstract Class" New topic

The Calendar abstract Class

Hicham bucarri

Joined: Jun 20, 2007
Posts: 5
In the K&B SCJP certification Book and exactly in chapter6 (Dates, Numbers, and Currency (Exam Objective 3.4))
the author says that "In order to create a Calendar instance, you have to use one of the overloaded getInstance() static factory methods:"
but, the Calendar Class is an abstact one, and you cannot create an instance of an abstract class what ever the method you use!!

can anybody explain the author's point of view?
victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
Its like doing

List ls = new ArrayList();

List is an interface.
Rafael Souza

Joined: Jul 03, 2007
Posts: 6
Actually when you call Calendar.getInstance(); what happens inside getInstance is that an object of a concrete class is created. Normally it�s an instance of java.util.GregorianCalendar, which is concrete.

Think like this: among other stuff, the method Calendar.getInstance() does something like return new GregorianCalendar(); So it doesn't try to instantiate Calendar (which is abstract), but GregorianCalendar (which is concrete).

Try to run the code that follows and you will notice that the result is: java.util.GregorianCalendar

Hicham bucarri

Joined: Jun 20, 2007
Posts: 5
Thank you victor!
Hicham bucarri

Joined: Jun 20, 2007
Posts: 5
Your version Rafael is better!
Thanks again
I agree. Here's the link:
subject: The Calendar abstract Class
It's not a secret anymore!