Given:

public class Test {

    public static void main(String[] args) {
        Integer num = Integer.parseInt(args[1]);
        System.out.println("Number is : " + num);
    }
}

And the commands:

javac Test.java
java Test 12345

What is the result?

A.

Number us : 12345

B. A NullPointerException is thrown at runtime
C. A NumberFormatException is thrown at runtime
D. An ArrayIndexOutOfBoundException is thrown at runtime.

题解

题目运行的指令会编译「Test.java」,由于「java」指令指定的类别是 Test,因此会运行 Test 类别的 main 方法,并把「12345」作为 main 的参数。参数的索引值从 0 开始。

程序第 4 行要取得参数索引 1 的值,但是这里的参数数量只有一个,因此会超出数组索引范围,而抛出 ArrayIndexOutOfBoundsException 例外。