Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Factory methods  RSS feed

 
Chetan Dodiya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
Preethi Dev
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but what is factory method???
 
Ankit Garg
Sheriff
Posts: 9608
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

eg

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!