File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes java.util.Calender Abstract confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "java.util.Calender Abstract confusion" Watch "java.util.Calender Abstract confusion" New topic
Author

java.util.Calender Abstract confusion

Mohd Fuzail
Ranch Hand

Joined: Feb 20, 2002
Posts: 107
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


Being defeated is often a temporary condition. Giving up is what makes it permanent.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Mohd Fuzail
Ranch Hand

Joined: Feb 20, 2002
Posts: 107
how can i see implemeted code of getInstance() method of java.util.Calender??
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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 )
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
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 ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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 ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java.util.Calender Abstract confusion