I cannot have both keywords on the same line: private final ... ()?

I know that when you create the final method in java, it cannot be overridden.

When the method is private , only methods and members of this class in which this method exists can access it.

So, does this mean that since the method cannot be accessed, it makes no sense to try to check if it can be overridden because I wrote the following declaration and I get the following warning:

private addCode method declared final

  private final void addCode(String code) { //codes here... } 
+6
source share
3 answers

Well, private means no one will get access to the method, but you, and no one can overload the final means. But since the only person with access to it is you, it makes no sense. You cannot be your own superclass.

It is like locking a document to write when you are the only person with access to the file.

+8
source

A private method cannot be overridden because it does not appear to child classes.

+2
source

A method cannot be overridden if it is finite, private, or static.

+1
source

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


All Articles