亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在接口中重寫默認方法,并在接口中執行默認方法

在接口中重寫默認方法,并在接口中執行默認方法

catspeake 2021-05-03 16:34:09
我想通過創建具體實現類的對象來執行接口中默認方法的定義主體,該對象也已覆蓋了該方法。無論是直接創建具體實現類的對象還是通過動態綁定/多態性,實現類中定義/覆蓋的主體都只會被執行。請看下面的代碼interface Banking {    void openAc();    default void loan()    {    System.out.println("inside interface Banking -- loan()");    }}class Cust1 implements Banking{    public void openAc()    {        System.out.println("customer 1 opened an account");    }    public void loan()    {        // super.loan(); unable to execute the default method of interface         //when overridden in implementation class         System.out.println("Customer1 takes loan");    }}//Cust1 concrete implementation classclass IntfProg8 {    public static void main(String[] args)     {        System.out.println("Object type=Banking \t\t\t Reference type=Cust1");        Banking banking = new Cust1();        banking.openAc();        banking.loan();    } }我想知道如何在Banking界面內的控制臺中打印以下內容-loan()當默認方法被覆蓋時
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 235 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號