I read a line in Kathy Sierra that "STATIC METHOD CANNOT BE OVERRIDDEN".
I had a debate with some of my friends on this topic.
They say: "Static method can be overridden but there is no use of it because Polymorphism does not apply to it".
But i say: "No, We simply cannot override Static methods and if we do so by modifying the subclass method as static then it is not called overriding but called as redefining of the method according to Kathy Sierra"
I go over the code:
The above code throws a compile error that "aMethod()" cannot be overridden; aMethod() in A is static.
If the compiler error has been developed so, why my friends do not agree with me?
I had an argument over this topic in one of my interviews too...
A very useful way of finding whether a method is actually overriden or redefined is the annotation.
Suppose you are overriding a method named myMethod() just add the annotation @Override before the method.If it can be overriden it runs else shows compilation error.