I tried writing a Singleton class using eager loading, see my solution below. I have made the constructor private to prevent access and the member field private, too, so it can't be accessed outside class scope.
public class Test {
private static Test t = new Test();
private Test() {
}
public static Test getInstance() {
return t;
}
}
So, is this piece thread safe, considering all the scenarios?