Calendar is an abstract class. The getInstance() method tries to instantiate GregorianCalendar() i.e., parent instantiating a derived class. This looks Non-OO? Ex: Calendar a=Calendar.getInstance(); Can somebody explain why is it so?

Sameer Tyagi

The Calender class is an abstact class, true, however,the point you missed is that the getInstance() returns the " Calendar using the default timezone and locale. " , in your case, the GregorianCalender a class that IS a Calender (a Suzuki IS a car, a 747 IS a plane..the standard OO terminology. So what you get is a class that does some specialized work based on the default locale. Other methods

 public static synchronized Calendar getInstance(TimeZone zone,Locale aLocale)
 public static synchronized Calendar getInstance(TimeZone zone)
return Calenders for specific timezones and locales. The closest parallel is possibly the Factory Method design pattern.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact