Given:

class MarksOutOfBoundsException extends IndexOutOfBoundsException {
}

public class GradingProcess {

    void verify(int marks) throws IndexOutOfBoundsException {
        if (marks > 100) {
            throw new MarksOutOfBoundsException();
        }
        if (marks > 50) {
            System.out.print("Pass");
        } else {
            System.out.print("Fail");
        }
    }

    public static void main(String[] args) {
        int marks = Integer.parseInt(args[2]);
        try {
            new GradingProcess().verify(marks);
        } catch (Exception e) {
            System.out.print(e.getClass());
        }
    }
}

And the command line invocation:

java GradingProcess 89 50 104

What is the result?

A.

Pass

B.

Fail

C. Class MarketOutOfBoundsException
D. Class IndexOutOfBoundsException
E. Class Exception

题解

此题输入的指令会使得 main 方法的 args 参数为「{"89", "50", "104"}」。然后将索引位置为 2 的字符串「104」转成数值「104」并指派给 marks 变量保存,再传给 GradingProcess 对象的 verify 方法。由于 marks 的值大于 100,因此会抛出 MarksOutOfBoundsException。