Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract - getInstance()

 
Lovleen Gupta
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They say DateFormat is an abstract class. So, to instantiate, you do:
DateFormat d = DateFormat.getInstance();

Also, somewhere I read that abstract classes can't be instantiated. So, there is an anomaly here. Please throw soe light on it.

Also, if the 2nd statement is incorrect,
does the getInstance() mehtod apply to instantiate any abstract class?

Thanks.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What getInstance() does is basically to return a new SimpleDateFormat.
So [i]DateFormat d = DateFormat.getInstance();[i] would be equivalent to [i]DateFormat d = new SimpleDateFormat(...)[i] with default parameters.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic