初始化阶段的意义
/*
* Copyright (c) 2019 maoyan.com
* All rights reserved.
*
*/
/**
* 在这里编写类的功能描述
*
* @author wangkai
* @created 2019/12/31
*/
public class MyTest5 {
public static void main(String[] args) {
Singleton singleton=Singleton.getInstance();
System.out.println(Singleton.counter1);
System.out.println(Singleton.counter2);
}
}
class Singleton{
public static int counter1;
private static Singleton singleton=new Singleton();
private Singleton(){
counter1++;
counter2++;
System.out.println(counter1);
System.out.println(counter2);
}
public static int counter2=0;
public static Singleton getInstance(){
return singleton;
}
}