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」並指派給mark變數儲存,再傳給GradingProcess物件的verify方法。由於mark的值大於100,因此會拋出MarksOutOfBoundsException。