• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

The Calendar abstract Class

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its like doing

List ls = new ArrayList();

List is an interface.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you victor!
 
Hicham bucarri
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your version Rafael is better!
Thanks again
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic