In Interface you are not actually redefining anything - an interface, by definition, cannot provide an implementation for any of its methods. The Demo class simply inherits the implementation of equals and toString from Object .
Essentially, an interface in Java contains a set of zero or more method signatures (all of them are implicitly abstract, in your code you made it explicit by adding the abstract keyword), and concrete classes that implement the interface must provide the implementation of these methods. In the case of your code, this implementation comes from Object , since all classes implicitly extend Object , which provides standard implementations for equals and toString (among other methods).
You really shouldn't mark methods in the interface with @Override , as you saw, this is confusing and serves a practical purpose. Instead, use @Override in methods of a particular class that implement interface methods, for example:
class Demo implements Interface { @Override public void show() { System.out.println("Method invoked."); } }
In addition, it is not necessary to declare equals and toString in the interface, so you are better off with this definition:
interface Interface { public void show(); }
source share