Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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
 
Water! People swim in water! Even tiny ads swim in water:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic