35) 阅读下列代码后
public class Person{
   int arr[]=new int[10];
   public static void main(String args[]){
      System.out.println(arr[1]);
   }
}
正确的说法是
  A)编译时将产生错误
  B)编译时正确,运行时将产生错误
  C)输出零
  D)输出空 
您的答案: C  正确答案: A  
INT数组默认不是0吗?

解决方案 »

  1.   

     staic 方法体应该引用static修饰的变量。static int arr[]=new int[10];
      

  2.   

    编译时就出错了
    不能在static方法中引用非static的东西!!
    以为每个不同对象的非static的东西可能不一样
    可以:
    System.out.println(new Person().arr[1]);
    或把arr声明明为static 
      

  3.   

    int arr[]=new int[10]; 要么是静态的,要么写在main方法里面。
      

  4.   

    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Cannot make a static reference to the non-static field arr
      

  5.   

    楼上正解Cannot make a static reference to the non-static field arr 
    不能在静态方法中应用非静态成员!
      

  6.   

    静态方法的考察,因为main()方法是statci所以main()方法中不能用非静态的,楼上正解