阅读下列代码后public class Person{ int arr[]=new int[10]; public static void main(String args[]){ System.out.println(arr[1]); }}正

admin2009-02-10  32

问题 阅读下列代码后public class Person{  int arr[]=new int[10];  public static void main(String args[]){    System.out.println(arr[1]);  }}正确的说法是

选项 A、编译时将产生错误
B、编译时正确,运行时将产生错误
C、输出零
D、输出空

答案A

解析 本题考查考生对Java中数组的定义及使用。int arr[]=new int[10]表示数组arr是一个含有10个元素的整数数组。Java中的数据类型必须实例化后才能使用,但是有种情况例外,就是该成员是用static声明的。题目中对于数组并没有实例化,因此不能使用,所以选项A说法正确。如果加上static修饰符,改为static int arr[]=new int[10]或者将该数组实例化即可,输出为0。
转载请注明原文地址:https://kaotiyun.com/show/EDnp777K
0

随机试题
最新回复(0)