wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes About Private Constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "About Private Constructors" Watch "About Private Constructors" New topic
Author

About Private Constructors

Hareendranath Babu Kotha
Ranch Hand

Joined: May 22, 2006
Posts: 40
What is the need of Private constructors ?


Hari.K,<br />+919886082889
Kaush Kane
Ranch Hand

Joined: May 22, 2006
Posts: 37
One use of private constructors that I know is while creating a singletone instance of a class. This is implemented as shown below:

class A{
private static A instance = null;
private int var;
private A() // private constructor
{
var = -1;
}
/* Getting singleton instance of class A */
public static A getInstance()
{
if(instance == NULL)
{
instance = new A()
}
return instance
}
}

Ramen Chatterjee
Ranch Hand

Joined: Apr 27, 2006
Posts: 62
Hi

There has just been a discussion about just this in the previous thread.

Ramen


Could try harder
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About Private Constructors