implicit super-interface in Java?

后端 未结 4 2037
情歌与酒
情歌与酒 2020-12-11 22:04

So we all know that all classes implicitly extend Object. How about interfaces? Is there an implicit super-interface? I say there is. The following code compiles:

         


        
4条回答
  •  心在旅途
    2020-12-11 22:50

    s1 and s2 here are object references, referring to instances of objects that implement Serializable. There is no such thing as an interface reference in Java.

    So Java knows that whatever these objects are, they descend from java.lang.Object. Hence the above code is valid.

提交回复
热议问题