I have found the @Override
annotation very much helpful while overriding some super class methods in my derived classes. Basically the compiler detects the flaw
Because you use @Override
for methods defined by interfaces as well.
(Yes, you're "implementing" rather than "overriding" ... but @Override
is used for both)
Since Java 6 you can use @Override on class methods implementing methods defined in interfaces
To implement an interface we use implements
and if any method exists in that interface then we override those methods to provide an implementation.
So there is only @Override
annotation because in both cases (class or interface) we always override.
To implement an interface the keyword already exists: implements
. but for override, no such keyword existed. @Override
is not a keyword but works similar.