扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
子类和父类有同名的成员变量,最终输出父类的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元起,快前往官网查看详情吧
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流