首页 > 编程语言 > 详细

Java-JVM 类的初始化

时间:2018-05-04 16:29:05      阅读:162      评论:0      收藏:0      [点我收藏+]
public class Test {
    protected static final Logger logger = LoggerFactory.getLogger(Test.class);

    public static void main(String[] args) {
        Singleton singleton = Singleton.getInstance();
        logger.info("counter1:" + singleton.counter1);
        logger.info("counter2:" + singleton.counter2);
    }
}

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

 

Java-JVM 类的初始化

原文:https://www.cnblogs.com/y8932809/p/8990975.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!