子类和父类有同名的成员变量,最终输出父类的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元起,快前往官网查看详情吧
当前标题:【c#】继承-创新互联
网页URL:https://www.cdcxhl.com/article2/doeooc.html
成都网站建设公司_创新互联,为您提供外贸建站、网站导航、定制网站、微信小程序、App设计、面包屑导航
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联