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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
Daniel Clinton
Posts: 29
Joined: Fri Aug 08, 2014 11:22 am
Contact:

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

Post 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)

admin
Site Admin
Posts: 10389
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests