/*
*
* @author caryt
*
*/
class test1{
String thh="caryt1";
}
/**
** @author caryt
*
*/
public class test {
static void test2(test1 t3){
t3.thh="caryt3";
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
test1 t1=new test1();
test1 t2=new test1();
t2.thh="caryt2";
System.out.println("t1:"+t1.thh+" t2:"+t2.thh);
t1=t2;
System.out.println("t1:"+t1.thh+" t2:"+t2.thh);
test2(t1);System.out.println("t1:"+t1.thh+" t2:"+t2.thh);
}
}
out:t1:caryt1 t2:caryt2
t1:caryt2 t2:caryt2
t1:caryt3 t2:caryt3
本文通过一个简单的Java程序示例展示了如何在不同对象间修改实例变量的值,并观察这些修改是如何影响各个对象的状态。
1018

被折叠的 条评论
为什么被折叠?



