Page 1 of 1

About Question enthuware.ocajp.i.v7.2.961 :

Posted: Fri Oct 24, 2014 10:27 am
by Daniel Clinton
While declaring a method, static usually implies that it is also final, this is not true for classes.
I thought about this for a while and I can see the rationale of it being final;
that a static method is always available
and it's bound to the type of the reference
and doesn't vary at runtime.
But on the other hand isn't there a difference between a final static method and a static method?
The final method cannot be hidden by a subclass method?
(javac actually reports 'cannot override' and 'overridden method is static,final'
for a static method matching the signature of a static final method in parent class)

Re: About Question enthuware.ocajp.i.v7.2.961 :

Posted: Sat Oct 25, 2014 10:17 am
by admin
The concepts of final and static are contradictory. You make something final to make sure that no one can override it. Overriding is one aspect of polymorphism. But static methods cannot be overridden at all because they are not polymorphic. In that sense, making a static method final doesn't make sense from a true OO point of view.

The error message from the compiler is not too good, imho. It should say "cannot hide" instead of "cannot override".

Having said the above, I must also add that I don't like the statement "While declaring a method, static usually implies that it is also final, this is not true for classes". It is too vague and confusing. Fixed.

thank you for your feedback!
Paul.