本帖最后由 Foundmoon 于 2015-6-13 15:40 编辑
赶快猜,一会公布答案和解释
class Person
{
int age;
Person(int age)
{
this.age=age;
}
}----------------------------------------------------------------------------
public class Test1
{
public static void main(String[] args)
{
Person p1=new Person(21);
show(p1);
System.out.println(p1.age);
}
static void show(Person p)
{
Person p3=new Person(28);
p=p3;
}
}
-----------------------------------------------------------------------------------------
public class Test2
{
public static void main(String[] args)
{
Person p1=new Person(21);
show(p1);
System.out.println(p1.age);
}
static void show(Person p)
{
p.age=28;
}
}-------------------------------------------------------------------------------------
public class Test3
{
public static void main(String[] args)
{
Person p1=new Person(21);
show(p1);
System.out.println(p1.age);
}
static void show(Person p)
{
Person p3=new Person(28);
p=p3;
p.age=99;
}
}
|
|