cast an object to an interface in java?

后端 未结 8 1696
半阙折子戏
半阙折子戏 2021-02-01 23:36

if we cast an object to an interface, won\'t this object be able to call its own methods? in the following example, myObj will only be able to call MyInterface meth

8条回答
  •  离开以前
    2021-02-02 00:14

    MyInterface mi = new Obj();
    mi.getInterfaceMethods(); (methods in the MyInterface)
    
    if(mi instanceof Obj) {
         mi.getObjMethods(); (methods in the Obj)
    }
    

提交回复
热议问题