Search code examples
javafunctionclassstaticfinal

Are static functions in a final class implicitly final?


My question is basically the same as this one, but does this also apply to static functions?

I want to understand:

  1. Does the compiler treat all the static functions in a final class as final?
  2. Does adding final keyword to static functions in a final class have any effect?

Solution

  • In a final class, all methods are implicitly final as well because making the class final means it cannot be inherited from and thus there can be no hiding or overriding of its methods in child classes.

    As a result, effectively you are correct that a static method in a final class is final, but it's not because of the fact that it's a static method. It's because the class is final.