If a class is declared final, methods must be declared final

I read and need some clarification regarding the latest classes and methods. My understanding is that declaring a class as final prevents the extension of this class. So you need to declare methods in the final class as final? It seems to me that if the class cannot be extended, there is no need to declare final methods.

+6
source share
3 answers

If a class is declared as final, there is no need to declare methods as final, because the class can no longer be extended.

+4
source

No, this is implied, so this is optional (but you can still do it if you like it).

+1
source

final means that the class cannot be extended, it means that there is no way to overload any method. Thus, it is redundant to have final method modifiers.

+1
source

Source: https://habr.com/ru/post/918055/


All Articles