java代码
public class son extends father {
string value = null;//2
public son() {
super(); //1
system.out.println(son: + value);//3
}
public static void main(final string[] args) {
new son();
}
}
class father {
public father() {
if (this instanceof son) {
son lower = (son) this;
lower.value = test;
}
}
}
class father {
public father() {
if (this instanceof son) {
son lower = (son) this;
lower.value = test;
}
}
}
下载
这个的结果是 null
步骤1 设置为test
步骤2 设置为null
步骤3 打印出来null
如果 不是 string value = null ; 只是 string value; 下载
步骤1 设置为test
步骤2 不做任何事情,因为已经有值了,不用设置为默认的null值了
步骤3 打印出来null
所以 一个字段不设置值 和 设置为null 是有区别的。