67,513
社区成员
发帖
与我相关
我的任务
分享
public class Test {
int i = 1;
Dog d;
Test(){}
Test(int i) {
this.i = i;
}
Test(int i, String name) {
this.i = i;
this.d = new Dog(name);
}
public static void main(String[] args) {
Test t = new Test();
System.out.print(t.i + "\t");
setTest(t);
System.out.print(t.i + "\t");
setTest(t, 5);
System.out.print(t.i + "\n");
t = new Test(2, "ahuang");
System.out.println(t.d);
setDog(t.d);
System.out.println(t.d);
setDog(t);
System.out.println(t.d);
}
public static void setTest(Test t) {
t = new Test(3);
}
public static void setTest(Test t, int i) {
t.i = i;
}
public static void setDog(Dog d) {
d = new Dog("heizi");
}
public static void setDog(Test t) {
t.d = new Dog("heizi");
}
}
class Dog {
int id;
static int count = 0;
String name;
Dog(String name) {
id = count++;
this.name = name;
}
public String toString() {
return this.id + "\t" + this.name;
}
}
/*
* outPut:~
* 1 1 5
* 0 ahuang
* 0 ahuang
* 2 heizi
*/