my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why are constructors declared private. Also is there any other way to achieve this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why are constructors declared private. Also is there any other way to achieve this" Watch "Why are constructors declared private. Also is there any other way to achieve this" New topic
Author

Why are constructors declared private. Also is there any other way to achieve this

Chiran Mathur
Ranch Hand

Joined: Feb 07, 2001
Posts: 63
Why should this be done? How can declaring a constructor private make it have only instance?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
When all constructors are private, you can only get an instance through a static method of the class. That static method can manage a pool of instances or ensure that only one instance is created.
Bill
 
Don't get me started about those stupid light bulbs.
 
subject: Why are constructors declared private. Also is there any other way to achieve this