• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getInstacne() for an abstract class

 
Grishma Dube
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a very basic question. We cannot create instance of an abstract class.
e.g. Calendar class of util pkg is ab abstract class. so if we try to create an instace of this using new operator, it gives error.
However, we can call getInstance() method to get an instance of Calendar class. Can anyone explain me, what exactly happens when we call getInstance() method??
TIA
Grishma
 
Marilyn de Queiroz
Sheriff
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default is to create a new GregorianCalendar (which is not abstract).
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that GregorianCalendar is a subclass of Calendar. This is an example of Polymorphism in the Java 2 Standard Edition API. Another example can be found with the public void paint(Graphics g) method that many windowing components have.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic