Hi Joydeep,
Thanks for reply and also understand that link but its not written clearly that in what senarios we required this private constructor. If we are making any class constructor as private accesss specifier then also we can create any number of object of that class then what is the benifits of that private constructor. If that class is allowing me to create any number of object after making that class constructor as private. But according to the rules of singleton object is telling that we can create only one object of that class but here we can create any number of object of this class. Like this example:
class A
{
int i = 10;
private A()
{
System.out.println("Hello World");
}
public static A getA()
{
return new A();
}
}
class Manager
{
public static void main(String args[])
{
A a1 = A.getA();
System.out.println(a1.i);
A a2 = A.getA();
System.out.println(a2.i);
}
}
In this scenarios we can create any number object of this class but according to rules of the singleton object is telling that we can create only one object of the singleton class. Then tell me what is the benifits of this private constructor.