【c#】继承-创新互联
一个case
本文标题:【c#】继承-创新互联
链接地址:http://scjbc.cn/article/doeooc.html
子类和父类有同名的成员变量,最终输出父类的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#】继承-创新互联
链接地址:http://scjbc.cn/article/doeooc.html