Behaviour of final static method
Static methods cannot be overridden but they can be hidden. The ts()
method of B is not overriding(not subject to polymorphism) the ts()
of A but it will hide it. If you call ts()
in B (NOT A.ts()
or B.ts()
... just ts()
), the one of B will be called and not A. Since this is not subjected to polymorphism, the call ts()
in A will never be redirected to the one in B.
The keyword final
will disable the method from being hidden. So they cannot be hidden and an attempt to do so will result in a compiler error.
Hope this helps.
static methods cannot be overriden
This is not exactly true. The example code really means that the method ts in B hides the method ts in A. So its not exactly overriding. Over on Javaranch there is a nice explanation.