The constructor's accessibility is the same as any class member

As the title of this section has stated, that is all we can say about the accessibility of a constructor. Naturally, when we talk about constructors, we talk only about classes.

The interesting thing about constructors is their ability to have private access only. It means that a class can provide its own factory method (see Chapter 6, Interfaces, Classes, and Object Construction), control how each object is constructed, and even control how many of them can be put into the circulation. The last feature is especially valuable in the case where each object requires access to a certain resource (a file or another database) that has limited support for concurrent access. Here is how the simplest version of such a factory method with a limited number of objects created may look:

private String field;
private static int count;
private PublicClass02(String s){
this.field = s;
}
public static PublicClass02 getInstance(String s){
if(count > 5){
return null;
} else {
count++;
return new PublicClass02(s);
}
}

The usefulness of this code is not great and we show it only to demonstrate how a privately accessible constructor can be used. It is possible because each class members can access all other class members no matter their access modifiers.

All the accessibility-related features would be not needed unless they brought some advantages. And that is what we are going to talk about in the next section  about the central concept of object-oriented programming, called encapsulation, which would be impossible without accessibility control.