您的位置:首页 > 编程语言 > Java开发

java笔试陷阱:对象引用作为参数传递时陷阱

2014-04-19 20:46 267 查看
public class Test5
{
public static void main (String args[])
{
Test5 test=new Test5();
test.method();
}
public void method()
{
int i=5;
May may=new May();
may.i=25;
this.testMethod(may,i);
System.out.println(may.i);//20一定要将指向关系的示意图画出来,清晰明了!
}
public void testMethod(May may,int i)
{
i=0;
may.i=20;
May be=new May();
may=be;
System.out.println(may.i+"  "+i);//输出15  0
}
}
class May
{
public int i=15;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: