Why Object class methods are available in interface?

前端 未结 5 1482
故里飘歌
故里飘歌 2021-01-24 23:25

Following interface and classes are successfully compiled. Problem is mentioned in the output below :

interface MyInterface{}

class MyClass imp         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-24 23:57

    The Java Language Specification clearly says that the members of an interface are those which are declared in the interface and those which are inherited from direct super interfaces. If an interface has no direct superinterface then the interface implicitly declares a public abstract member method corresponding to each public instance method declared in the Object class, unless a method with the same signature, same return type, and a compatible throws clause is explicitly declared by that interface.

提交回复
热议问题