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」方法。