class test
{
static x;
 test()
   {
     x=x+1;
   }
}
void main()
{
test[] a=new test[10];
System.out.println(test.x)//为什么还是0?}

解决方案 »

  1.   

    创建了数组,每个元素还是null,需要单独new。
      

  2.   

    for(int i=0;i<10;i++){
    test[i] t=new test();}
    }
    单独new是这样写么 新手呵呵 请教
      

  3.   

    for(int i=0;i<10;i++)
    {
       test[i]=new Test();
    }加个这个循环语句打印出来就是10了,
      

  4.   

    创建了数组,但是数组中每个对象为null,为实例化啊
      

  5.   

    new test[10]只是创建了10个为null的test对象。对每个元素new test()才行。class test{
    static int x;
    public test(){
       x=x+1;
      }
    }
    public class ok{
    public static void main(String[] args){
    test[] a=new test[10];
    System.out.println(a[0]);
    for(test t:a){
    t=new test();
    }
    System.out.println(test.x);
    test s1=new test();
    test s2=new test();
    System.out.println(test.x);
    }
    }
      

  6.   

    所有 LS 已经说得很清楚了。test[] a=new test[10];就像你做了个只能用来放10个test的箱子,但是你还没有把test放到箱子里面。