當(dāng)前位置:首頁(yè) > IT技術(shù) > 其他 > 正文

多態(tài)多態(tài)多態(tài)多態(tài) 的 向上轉(zhuǎn)型 一個(gè)小栗子....
2022-05-31 17:26:25

public?class?Main?{

????public?static?void?main(String[]?args)?{
????????test?test?=?new?test();
????????test.xxx(new?zi());


????}
}

class?fu{
????public?void?x(){
????????System.out.println("我是父");
????}
}

class?zi?extends?fu{
????public?void?x(){
????????System.out.println("我重寫了父類的x方法");
????}
????public?void?xx(){
????????System.out.println("我是子");
????}
}

class?test{
????public?void?xxx(fu?xxx){
????????xxx.x();
????}
}

每天學(xué)多一點(diǎn)點(diǎn) 哪怕一點(diǎn)點(diǎn) 我都是進(jìn)步.........?

?

成功以基礎(chǔ)首 誰(shuí)不是那樣過(guò)來(lái)的呢...


作者:??咸瑜???


本文摘自 :https://blog.51cto.com/u

開(kāi)通會(huì)員,享受整站包年服務(wù)立即開(kāi)通 >