Given:

public static void main(String[] args) {
    String theString = "Hello World";
    System.out.println(theString.charAt(11));
}

What is the result?

A. The program prints nothing
B.

d

C. A StringIndexOutOfBoundsException is thrown at runtime.
D. An ArrayIndexOutOfBoundsException is thrown at runtime.
E. A NullPointerException is thrown at runtime.

题解

theString 变量所参考到的字符串为长度是 11 的「Hello World」,程序第 7 行要取得「Hello World」索引位置为 11 的字符,会超出字符串长度,因此会抛出 StringIndexOutOfBoundsException 例外。