my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Why Sun made Calendar class as a abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why Sun made Calendar class as a abstract class" Watch "Why Sun made Calendar class as a abstract class" New topic

Why Sun made Calendar class as a abstract class

jitendra vishnoi

Joined: Jan 19, 2010
Posts: 10
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.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19656

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Why Sun made Calendar class as a abstract class
Similar Threads
abstract class instance
Why is Calendar an abstract class ?
Instance of an abstract class
Calendar class problem?