子類(lèi)和父類(lèi)有同名的成員變量,最終輸出父類(lèi)的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);
}
}
}
子類(lèi)不寫(xiě)同名字段name,輸出子類(lèi)的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);
}
}
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
當(dāng)前標(biāo)題:【c#】繼承-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)URL:http://chinadenli.net/article2/doeooc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、網(wǎng)站導(dǎo)航、定制網(wǎng)站、微信小程序、App設(shè)計(jì)、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容