Yes, you can make your contructor private; this is typically what you do when implementing the Singleton
pattern.
Example:
public class MyClass {
private MyClass myInstance = null;
private MyClass() {
}
public static MyClass getInstance() {
if (myInstance == null) {
myInstance = new MyClass;
}
return myInstance;
}
}
And to use, put the following in your main method:
MyClass myClass = MyClass.getInstance();
Notice that you call getInstance() instead of "new MyClass()", which you wouldn't be able to do without a compiler error.
-Rich,
SCJP