cast an object to an interface in java?

后端 未结 8 1720
半阙折子戏
半阙折子戏 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:29

    There is no difference. You will only be able to invoke MyInterface interface methods on myObj and mySec. Obviously your code will only compile if both Obj and Sec implement the Myinterface interface.

提交回复
热议问题