I have been studying for my Software Development course and came across the question from a sample:
“Why does it make no sense to have both the static and final modifiers in front of a Java method?”
I have had a bit of a research and everywhere I go it says it is not bad practice and there are good reasons for doing so – for example, this stackoverflow question:
Is it a bad idea to declare a final static method?
So, is this question itself nonsensical or is there a legitimate answer to this question?
(There are no given solutions to this sample paper)
staticmethods cannot be overriden since they’re associated not with an instance of class, but with the class itself. For example, this is how you’d usually callstaticmethod:And this is how you call an instance method:
finalmodifier is used with methods to disallow their override in extending classes.