我想通過創建具體實現類的對象來執行接口中默認方法的定義主體,該對象也已覆蓋了該方法。無論是直接創建具體實現類的對象還是通過動態綁定/多態性,實現類中定義/覆蓋的主體都只會被執行。請看下面的代碼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()當默認方法被覆蓋時
添加回答
舉報
0/150
提交
取消