cast an object to an interface in java?

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

    Changing the type of a variable (i.e. a reference) does not change the object itself. An object can always call its own methods, no matter what the types of declared variables are that reference to it.

提交回复
热议问题