首页 > 代码库 > 初始化

初始化

package JVM;


class Singleton {


public static Singleton singleton = new Singleton();

public static int a;

public static int b = 0;

private Singleton(){

super();

a++;

b++;

}

public static Singleton getInstance(){

return singleton;

}

}


public class TestSingleton{

public static void main(String[] args) {

Singleton s = Singleton.getInstance();

System.out.println(s.a);

System.out.println(s.b);

}

}



程序输出:

1

0


初始化