一个JAVA编程的问题?

来源:百度知道 编辑:UC知道 时间:2024/05/10 11:08:38
Given:
public class Test{
public static void main(String[]args){
string foo="blue";
string bar=foo;
foo="green"
System.out.printIn(bar);
}
}
what is the result?

blue
我的理解是:在JAVA中,String 对象的值不可以改变,string foo="blue"在堆栈区建立一个字符串“blue”对象,并且foo指向这个对象的;string bar=foo,使bar也指向blue这个对象;foo="green"在堆栈区建立一个新的“green”对象,并让foo指向它,而bar没有变化,仍然指向"blue".
共同学习ing

there should be some errors.

bar points to the "blue";
foo points to the "green"

经典275 考题啊,

blue