成都网站建设设计

将想法与焦点和您一起共享

【c#】继承-创新互联

一个case

子类和父类有同名的成员变量,最终输出父类的namekaka

创新互联专注于企业成都全网营销、网站重做改版、荆门网站定制设计、自适应品牌网站建设、HTML5商城系统网站开发、集团公司官网建设、成都外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为荆门等各大城市提供网站开发制作服务。
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://chengdu.cdxwcx.cn/article/doeooc.html