接口初始化规则与类加载器准备阶段和初始化阶段的重要意义

初始化阶段的意义

/*
 * 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;
    }

}
发布了212 篇原创文章 · 获赞 37 · 访问量 18万+

猜你喜欢

转载自blog.csdn.net/qq_23864697/article/details/104746157