Java – final static method test
I've been studying for my software development course and got this problem from the example:
"Why do you have both static and final modifiers before Java methods?
I have a research everywhere. I say it says it's not a bad practice and there are good reasons to do so - for example, this stackoverflow problem: is it a bad idea to declare a final static method?
So is this question absurd in itself, or is there a reasonable answer to this question?
(this sample document does not give a solution)
Solution
Static methods cannot be overridden because they are not associated with an instance of the class, but with the class itself For example, this is often referred to as a static method:
MyClass.myStaticMethod()
This is how you call an instance method:
new MyClass().myInstanceMethod()
The final modifier is used to prohibit its override in the extension class