• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Why Sun made Calendar class as a abstract class

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to know why Sun make Calendar(or DateFormat or NumberFormat etc.) class as a abstract class. This class can also be as a normal class and its methods can also be have some implementation. We can also get instance of Calendar class by Calendar.getInstance() without extending the Calendar class.
 
Sheriff
Posts: 22803
131
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Calendar is abstract because there is no global calendar system. Most use the Gregorian calendar; that's why it has a matching concrete class GregorianCalendar. There are at least two other active calendars - the Buddhist calendar and the Japanese imperial calendar. Those too have matching (non-public) classes in Java.

DateFormat and NumberFormat are abstract because, well, that's how it's designed. They are meant to be used as the root of entire formatter hierarchies*. They provide no direct implementation; instead that's up to subclasses like SimpleDateFormat (the most often used DateFormat subclass) and DecimalFormat (the most often used NumberFormat subclass). But because DateFormat and NumberFormat are abstract it's easy to write and use a different one.


* Actually sub hierarchies, with java.text.Format being the root of the entire formatter hierarchy.
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic