aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 12682
    
    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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why are constructors declared private. Also is there any other way to achieve this
 
Similar Threads
question about abatract
Final Question
Private Constructor trap
Native Method
access control modifier for enum