Java – I can’t have two keywords on the same line: Private Final… ()?
•
Java
I know that when you create a method final in Java, it cannot be overwritten
When a method is private, it can only be accessed by the methods and members of the given class in which the method is located
So, does this mean that it is useless to try to check whether it can be overwritten because the method cannot be accessed, because I wrote the following declaration and got the following warning:
private final void addCode(String code) { //codes here... }
Solution
Well, private means that no one except you will access the method, which ultimately means that no one can overload the method But because the only person who can access it is you, it makes no sense You can't be your own superclass
Just like locking a document, only people with access can write
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码