I have read about private constructors on many websites, and also referred various questions on StackOverflow. However, I failed to understand their usage. Most websites say that a private constructor can be used when we want to restrict the number of instances of objects that can be created.
I tried the following program:
public class PrivateCons{
private PrivateCons(){
System.out.println("I'm executed");
}
public static void main(String[] args) {
PrivateCons p=new PrivateCons();
PrivateCons q=new PrivateCons();
}
}
My program executes perfectly well. Have I understood the concept wrong?