aspose file tools
The moose likes Beginning Java and the fly likes private constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "private constructor" Watch "private constructor" New topic
Author

private constructor

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
what is the use of private constructor
Regards,
aakash
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24057
    
  13

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.


[Jess in Action][AskingGoodQuestions]
Rob Michaelson
Ranch Hand

Joined: Jul 15, 2003
Posts: 36
I found a good glossary from SUN that mat help with terms
http://java.sun.com/docs/glossary.html#P
Rob
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: private constructor
 
Similar Threads
constructor private ?
constructor private ?
Private Constructor
Making a class non extensible without using final
purpose of private constructor in abstract class