| 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: 6592
|
|
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 - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
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: 6592
|
|
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.
|
 |
 |
|
|
subject: java.util.Calender Abstract confusion
|
|
|