阅读下面的程序: public class Person{ int arr[ ]=Hew int[10]; public static void main(String args[ ]){

admin2010-12-17  37

问题 阅读下面的程序:        public class Person{             int arr[ ]=Hew int[10];             public static void main(String args[ ]){                  System.out.println(arr[1]);             }        }    正确的说法是______。   

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

答案A

解析  由于数组arr声明时未使用static关键字,而main( )方法直接引用arr(而非通过 Person的实例引用),将产生“非静态变量不能从静态上下文中引用”  (non-static variable cannot be referenced from a static context)的编译错误。
转载请注明原文地址:https://jikaoti.com/ti/7RH0FFFM
0

最新回复(0)