美文网首页
了解类加载机制

了解类加载机制

作者: 海边的贝壳林 | 来源:发表于2017-08-28 16:59 被阅读0次

    知道下面的程序输出的内容么?

    public class Singleton {
      private static Singleton singleton = new Singleton();
      public static int counter1;
      public static int counter2 = 0;
      private Singleton() {
          counter1++;
          counter2++;
      }
      public static Singleton getSingleton() {
          return singleton;
      }
     }
    
      public class TestSingleton {
        public static void main(String args[]){
            Singleton singleton = Singleton.getSingleton();
            System.out.println("counter1="+singleton.counter1);
            System.out.println("counter2="+singleton.counter2);
        }
    }
    

    相关文章

      网友评论

          本文标题:了解类加载机制

          本文链接:https://www.haomeiwen.com/subject/kiygdxtx.html