SCJP(OCPJP) 考古題解析 第2題

Given:

public class TestString1 {
    public static void main(String[] args) {
        String str = "420";
        str += 42;
        System.out.print(str);
    }
}

What is the output?


A. 42
B. 420
C. 462
D. 42042
E. Compilation fails.
F. An exception is thrown at runtime.


答案


解析:

注意str宣告為String,String的+為字串的連結



0 意見:

張貼留言