• Post Reply Bookmark Topic Watch Topic
  • New Topic

private constructor  RSS feed

 
aakash bhatt
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the use of private constructor
Regards,
aakash
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A class with a private constructor can't be instantiated by code outside that class. There are many uses for this: either to prevent a class from being instantiated altogether (java.lang.System, java.lang.Math) or to control the circumstances under which it's created (java.lang.reflect.Method).
A common application of this in user code is to let you create a Singleton -- a class of which only one instance can possibly exist.
 
Rob Michaelson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a good glossary from SUN that mat help with terms
http://java.sun.com/docs/glossary.html#P
Rob
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!