子类和父类有同名的成员变量,最终输出父类的namekaka
using UnityEngine;
namespace Tests.mapilot
{public abstract class Father
{public string name;
public Father(string name)
{this.name = name;
Debug.Log("father:" + this.name);
}
}
public class Children : Father
{public string name;
public Children(string name) : base(name)
{this.name = "chilid-" + name;
Debug.Log("chilid:" + this.name);
}
}
public class UnitTest
{public static void Start()
{Father c = new Children("kaka");
test(c);
}
public static void test(Father f)
{Debug.Log(f.name);
}
}
}
子类不写同名字段name,输出子类的namechile-kaka
using UnityEngine;
namespace Tests.mapilot
{public abstract class Father
{public string name;
public Father(string name)
{this.name = name;
Debug.Log("father:" + this.name);
}
}
public class Children : Father
{public Children(string name) : base(name)
{this.name = "chilid-" + name;
Debug.Log("chilid:" + this.name);
}
}
public class UnitTest
{public static void Start()
{Father c = new Children("kaka");
test(c);
}
public static void test(Father f)
{Debug.Log(f.name);
}
}
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款