一道面试题
题目的代码大致如下:
1 public class StringTest { 2 3 public static void process(String str){ 4 str="A"; 5 } 6 7 public static void process(StringBuffer sb){ 8 sb=new StringBuffer("A"); 9 sb.append("a"); 10 } 11 12 public static void process(String str,StringBuffer sb){ 13 14 sb.append("a"); 15 } 16 17 public static void main(String[] args) { 18 String str="a"; 19 StringBuffer sb=new StringBuffer("a"); 20 process(str); 21 System.out.println(str); 22 process(sb); 23 System.out.println(sb); 24 process(str,sb); 25 System.out.println(sb); 26 } 27 }
猜想输出结果和实际运行一致:
a
a
aa