Given:

public class Whizlabs {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder("1Z0");
        sb.concat("-808");
        System.out.println(sb);
    }
}

What is the output?

A.

1Z0

B.

1Z0-808

C. An exception will be thrown.
D. Compilation fails due to error at line 3.
E. Compilation fails due to error at line 4.

题解

StringBuilder 对象并没有「concat」方法,因此程序第 4 行会编译错误。如果要串接字符串应使用 StringBuilder 的「append」方法。