For example:
public class Singleton {
private static final Singleton INSTANCE = new Singleton();
// Private constructor suppresses
// default public constructor
private Singleton() {};
public static Singleton getInstance() {
return INSTANCE;
}
}
Why can't I set the INSTANCE
public, and access it by Singleton.INSTANCE
? What will it cause?