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.

執行結果:

Ans: D
老唬碎碎唸:
這個是兩字串相加,而非 420 + 42 的數字相加。
而是字串 “420” 加上字串 “42”,會產生一個新的字串 “42042”。
0 意見:
張貼留言