• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Abstract class Calendar

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I have a doubt about Calendar class.

Java API states that Calendar is an abstract class then how can we create instance of Calendar ? It has two types of constructors and a method getInstance() which return calendar object.

Can someone explain me what I am missing?

-Vivian
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Abstract classes cann't be instantiated.It can be only subclassed.So We are using its(Calendar) subclass GregorianCalendar to get Abstract class instance.Its like we are assigning subclass object to super class referrence.

Calendar cn=Calendar.getInstance();
System.out.println(cn.getClass());

then it shows its subclass name i.e GregorianCalendar.
 
Vivian Josh
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kathir, for quick reply !

cn.getClass() was good!
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic