问题
单项选择题
阅读下面代码 public class Person { static int arr[]=new int[10]; public static void main(String args) { System.out.println(arr[9]); } } 该代码的运行结果是
A.编译时将产生错误
B.编译时正确,运行时将产生错误
C.输出零
D.输出空
答案
参考答案:B
解析: Java程序中,main()方法的格式为public staric void main(String args[]) { },返回值为void,参数必须为字符数组。本题目程序的参数不是字符数组,编译不会出错,但是运行时会找不到main()方法,程序无法执行。