标签:string void stat turn null 理解 tostring sys value
class A{
private String name;
private String value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public A(String name){
this.name = name;
}
@Override
public String toString() {
return "A{" +
"name=‘" + name + ‘\‘‘ +
", value=‘" + value + ‘\‘‘ +
‘}‘;
}
}
class B{
private Object data;
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
@Override
public String toString() {
return "B{" +
"data=" + data +
‘}‘;
}
}
public class ThinkTest {
public static void main(String[] args) {
A a1 = new A("第一个A对象");
System.out.println(a1);
B b = new B();
b.setData(a1);
System.out.println(b);
a1 = new A("第二个A对象");
a1.setValue("success");
System.out.print(b);
}
}
A{name=‘第一个A对象‘, value=‘null‘}
B{data=A{name=‘第一个A对象‘, value=‘null‘}}
B{data=A{name=‘第一个A对象‘, value=‘null‘}}
标签:string void stat turn null 理解 tostring sys value
原文地址:http://www.cnblogs.com/TearsOfEyes/p/7707431.html