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吗?
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吗?
不能在static方法中引用非static的东西!!
以为每个不同对象的非static的东西可能不一样
可以:
System.out.println(new Person().arr[1]);
或把arr声明明为static
Cannot make a static reference to the non-static field arr
不能在静态方法中应用非静态成员!