This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 14687

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
It is sorta covered in the JavaRanch Style Guide.
subject: abstract - getInstance()
Similar Threads
Simple Question regarding Abstract class
about abstract local classes
DateFormat question
how do abstract classes like NumberFormat call the methods from their subclasses?
Factory Methods