• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Factory methods

 
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: 9521
22
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic