您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

java对象初始化的顺序

2025/8/22 20:10:50发布18次查看
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  是有区别的。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product