• 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

java.util.Calender Abstract confusion

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.util.Calender is an abstract class with a method getInstance() which returns an instance of the Calender class

If an class is abstract, how can we get an instance of that class without implementing the abstract class
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The getInstance method will return the implemented class for you. This way of getting an instantiated object is to make sure that it cant be instantiated like this...

Calender c = new Calender();

Thats because classes with private constructors cant be instantiated with the preceding code.

You can control the type of object to send, and you can instantiate it properly before sending it.
 
Mohd Fuzail
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i see implemeted code of getInstance() method of java.util.Calender??
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at the src.zip file that comes with the JDK. Browse the right package to find Calender.java ( I wouldnt go that far to see the implementation though )
 
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the directory where the JDK is installed, there should be a file named 'src.zip'.

Unzip it.

Most of the Java source code is in there.

Guy

:-) Ah well, I am late with this post......
[ September 24, 2006: Message edited by: Guy Allard ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Run this code:


You can then see what type of Calendar the getInstance() method returns.
Change the Locale parameters to see if you can get another type of Calendar.
[ September 24, 2006: Message edited by: Barry Gaunt ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic