首先来看笔者遇到的一道面试题,阅读下面的代码并给出执行结果:
class Singleton {
private static Singleton singleton = new Singleton();
public static int counter1;
public static int counter2 = 0;
private Singleton() {
counter1++;
counter2++;
}
public static Singleton getInstance() {
return singleton;
}
}
public class TestSingleton {
public static void main(String[] args) {
Singleton s ...