Reputation: 3255
All classes in java extend the Object class implicitly. But that doesn't concern interfaces. Interfaces can only extend other interfaces, but no classes. However, I can override object class methods inside my interface.
public interface NewInterface {
@Override
boolean equals(Object var1);
@Override
int hashCode();
}
Can you please explain in simple words how is this even possible? Is there any use case for this?
Upvotes: 1
Views: 876
Reputation: 38104
Interface is a just contract. It says that all classes that inherits interface should implement these methods. Interface cannot have implementation. It is possible to override a class that implements this interface.
However, from Java 8 you can define static methods in interfaces in addition to default methods.
UPDATE:
The members of an interface are:
Read more about interface members here
Upvotes: 2