package com.bird.classLoad;
public class Test1 {
@SuppressWarnings("static-access")
public static void main(String[] args) {
Singleton s = Singleton.getSingleton();
System.out.println("counter1 = "+ s.counter1);
System.out.println("counter2 = "+s.counter2);
}
}
class Singleton{
private static Singleton singleton = new Singleton();
public static int counter1;
public static int counter2 = 0;
public Singleton(){
counter1++;
counter2++;
}
public static Singleton getSingleton(){
return singleton;
}
}
这段代码的答案是什么,为什么会这样呢? |
|