File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes abstract - getInstance() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "abstract - getInstance()" Watch "abstract - getInstance()" New topic

abstract - getInstance()

Lovleen Gupta
Ranch Hand

Joined: Feb 26, 2007
Posts: 63
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?

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

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.

[My Blog]
All roads lead to JavaRanch
I agree. Here's the link:
subject: abstract - getInstance()
It's not a secret anymore!