标签:
1 class A 2 { 3 public static final int VAL = 3; // 不会导致A被加载 4 static 5 { 6 System.out.println("load A"); 7 } 8 public A() 9 { 10 System.out.println("create A"); 11 } 12 } 13 class B 14 { 15 public static final A AOBJ = new A(); //会导致B被加载 16 static 17 { 18 System.out.println("load B"); 19 } 20 public B() 21 { 22 System.out.println("create B"); 23 } 24 } 25 public class Test 26 { 27 public static void main(String[] args) 28 { 29 System.out.println(A.VAL); 30 System.out.println("---------------------"); 31 System.out.println(B.AOBJ); 32 } 33 }
标签:
原文地址:http://www.cnblogs.com/itpoorman/p/4534625.html