This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Factory methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Factory methods" Watch "Factory methods" New topic

Factory methods

Chetan Dodiya
Ranch Hand

Joined: Jun 27, 2008
Posts: 39
I came across one question...
Which classes are always instantiated via Factory method???
a, java.util.Date
b, java.util.Locale
c, java.util.Calender
d, java.text.DateFormat
e, java.text.NumberFormat

this q is from of K & B book....
what is the Factory method???/
which is the correct answer???

SCJP 1.5
Preethi Dev
Ranch Hand

Joined: Sep 07, 2008
Posts: 265
c,d,e are always instantiated via the static factory methods getInstance(),getDateInstance(),getCurrencyInstance(). These classes are abstract. So we are using these methods to instantiate them.

preparing Scjp1.5
Chetan Dodiya
Ranch Hand

Joined: Jun 27, 2008
Posts: 39
but what is factory method???
Ankit Garg

Joined: Aug 03, 2008
Posts: 9434

Factory methods are methods which return instances of a class. Just as a factory produces items, Factory method produces instances. The general naming convention for factory methods is getInstance.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: Factory methods
It's not a secret anymore!