使用test类的静态成员或产生test类实例才会执行

解决方案 »

  1.   

    你并没有调用test.i or test.j,static只是保证在没有产生事例的情况下可以调用运行,我想jvm也是直道你调用那一刻才把代码装入!
      

  2.   

    static的意思是这个方法或属性不需要创建类实例就可以直接使用,而不是会自动执行
      

  3.   

    可这个就自动运行拉啊
    class test
          {
            public static int i=method1();
            private static int j=method2();
            public static int method1()
           {
                    System.out.println("test.method1");
            return 4;
           }
           private static int method2()
           {
                    System.out.println("test.method2");
            return 6;
            
           }
          } 
          public class test1 extends test
          {
            int e=method3();
            static int w=method3();
            public static int method3()
            {
                     System.out.println("test1.method3");
             return 6;
            }
            
            test1()
            {
                     System.out.println("test1.test1()");
            }
          
            public static void main(String args[])
           {
                    test1 t1=new test1();
                   test1 t2=new test1();
                  }
          }
      

  4.   

    你在main中创建一个实例就可以了
    Test ob=new Test();试试。
      

  5.   

    先应行的是静态块,不是静态方法
    静态块:
    static{
      public static int i=0;
         .
         .
    }