一道JAVA 考試題 請高手指點

JAVA菜菜子發表於2005-02-02
在amay的scjp試題中有這樣一道題目:

Click the exhibit button:
1. public class test {
2. public static void stringReplace (String text) {
3. text = text.replace (‘j’ , ‘i’);
4. }
5.
6. public static void bufferReplace (StringBuffer text) {
7. text = text.append (“C”)
8. }
9.
10. public static void main (String args[]) {
11. String textString = new String (“java”);
12. StringBuffer textBuffer = new StringBuffer (“java”);
13.
14. stringReplace (textString);
15. bufferReplace (textBuffer);
16.
17. System.out.println (textString + textBuffer);
18. }
19. }
What is the output

答案是javajavaC,我不清楚為什麼textString的內容沒有改變而textBuffer的內容改變了,我是菜鳥弄不明白阿

請高手指點謝謝了

相關文章