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

Confusion in Calender Class

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

I ahve one question. Calender class in java is abstract class. But if you want to use it then you are creating its instance using
Calendar rightNow = Calendar.getInstance();

Here is the few lines which are in help on Suns site:

A Calendar object can produce all the time field values needed to implement the date-time formatting for a particular language and calendar style (for example, Japanese-Gregorian, Japanese-Traditional). Calendar defines the range of values returned by certain fields, as well as their meaning. For example, the first month of the year has value MONTH == JANUARY for all calendars. Other values are defined by the concrete subclass, such as ERA and YEAR. See individual field documentation and subclass documentation for details.


The method details:

getInstance

public static Calendar getInstance()

Gets a calendar using the default time zone and locale. The Calendar returned is based on the current time in the default time zone with the default locale.

Returns:
a Calendar.

Here is my question:
(1) If the Calender class is abstract how it clould be possible to create a calender object???

Can anybody give me the exact explanation about this? How to create a object of the abstract class. or how the calender object create here???

Malhar
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Calendar class has 8 or so abstract methods. You can create an instance of an abstract class by either sub-classing it normally or using anonymous inner class. And as far as Calendar goes, it returns an instance of one of the concrete sub-class GregorianCalendar. I don't know if there is any exception to this...
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:Calendar class has 8 or so abstract methods. You can create an instance of an abstract class by either sub-classing it normally or using anonymous inner class. And as far as Calendar goes, it returns an instance of one of the concrete sub-class GregorianCalendar. I don't know if there is any exception to this...



Not satisfied with this explanation. Want a better one. Nice question by the way.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

aabir sanyal wrote:Not satisfied with this explanation. Want a better one. Nice question by the way.



It would help if you explain what you are not satisfied with.... We can't elaborate, if we don't know what you don't understand.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Here is my question:
(1) If the Calender class is abstract how it clould be possible to create a calender object???



Keep in mind that subclasses of a superclass IS-A superclass type too. So, returning an instance of a subclass (concrete) of the calendar class IS returning a calendar object.

Henry
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Calendar.getInstance() method basically looks like this:

GregorianCalendar is a non-abstract subclass of Calendar.
 
aabir sanyal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Angstadt wrote:The Calendar.getInstance() method basically looks like this:

GregorianCalendar is a non-abstract subclass of Calendar.



Perfect, thanks.
 
Malhar Me
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the answer.
 
reply
    Bookmark Topic Watch Topic
  • New Topic