谁帮我看看题目,我不明白为什么Cookie 类的静态代码没有执行,
看到这个题目,我也不明白为什么Cookie   类的静态代码没有执行.如果类加载了这个static代码就应该执行啊。如果没加载,怎么能使用Cookie.class属性呢 
 class   Candy   {    
 static    
 {    
 System.out.println( "Loading   Candy ");    
 }    
 }      
 class   Gum    
 {    
 static    
 {    
 System.out.println( "Loading   Gum ");    
 }    
 }      
 class   Cookie    
 {    
 static    
 {    
 System.out.println( "Loading   Cookie ");    
 }    
 }      
 public   class   SweetShop   {    
 /**    
 *   @param   args    
 */    
 public   static   void   main(String[]   args)   {    
 //   TODO   Auto-generated   method   stub    
 System.out.println( "inside   main ");    
 new   Candy();    
 System.out.println( "After   creating   Candy ");    
 try    
 {    
 Class.forName( "Gum ");    
 }    
 catch(
ClassNotFoundException   e)    
 {    
 e.printStackTrace();    
 }    
 System.out.println( "After   Class.forName(\ "Gum\ ") ");    
 Class   c   =   Cookie.class;    
 System.out.println( "Cookie   toString():    "   +   c);    
 System.out.println( "After   creating   Cookie ");    
 }      
 }    
------解决方案--------------------ry 
 { 
 Class.forName( "Gum "); 
 } 
 catch(Class
NotFoundException e) 
 { 
 e.printStackTrace(); 
 }  
 这段代码有问题,出现异常
------解决方案--------------------测试了下,发现 类.class 这个东西,不能代表对类的访问 
 实际上,在编译期,这个已经决定下来了   
 再比如 static final int 的常量,你访问,并不会造成对指定类的载入,这个东西再编译期已经内联了
------解决方案--------------------这里讨论过了: 
 http://community.csdn.net/Expert/topic/5478/5478850.xml?temp=.9950983
------解决方案--------------------回复人:redduke1202(勿以分少而不回★★勿以分多而灌水) ( ) 信誉:100	2007-04-28 17:35:32	得分:0 
 ?		测试了下,发现 类.class 这个东西,不能代表对类的访问 
 实际上,在编译期,这个已经决定下来了   
 再比如 static final int 的常量,你访问,并不会造成对指定类的载入,这个东西再编译期已经内联了 
 ------------------------------------------------ 
 有道理!绝对支持! 
 这是你的那个SweetShop类反编译的结果:看了就知道了. 
 import java.io.PrintStream;   
 public class SweetShop 
 {   
     public SweetShop() 
     { 
     }   
     public static void main(String args[]) 
     { 
         System.out.println( "inside main "); 
         new Candy(); 
         System.out.println( "After creating Candy "); 
         try 
         { 
             Class.forName( "Gum "); 
         } 
         catch(ClassNotFoundException classnotfoundexception) 
         { 
             classnotfoundexception.printStackTrace(); 
         } 
         System.out.println( "After Class.forName(\ "Gum\ ") "); 
         Object obj = Cookie;// <-------------------------------------------------------这儿! 
         System.out.println((new StringBuilder()).append( "Cookie toString():  ").append(obj).toString()); 
         System.out.println( "After creating Cookie "); 
     } 
 }
------解决方案--------------------