Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.util.Calender Abstract confusion

 
Mohd Fuzail
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • 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
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
how can i see implemeted code of getInstance() method of java.util.Calender??
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • 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 )
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • 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 ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic