本文共 721 字,大约阅读时间需要 2 分钟。
/* * 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; }}
转载地址:http://tobjn.baihongyu.com/