Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't I have both keywords on the same line : private final...()?

Tags:

java

I do know that when you make a method final in java, it cannot be overridden.

When a method is private, it can only be accessed by methods and members of that given class in which the method exists.

So, does it mean that since the method cannot be accessed it is no use trying to check if it can be overridden because I wrote the following declaration and I get the following warning :

private method addCode is declared final

 private final void addCode(String code)
     {
        //codes here...
     }
like image 506
helpdesk Avatar asked Mar 16 '12 14:03

helpdesk


2 Answers

Well, private means no-one is going to access the method apart from you and final means no-one can overload the method. 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 for writes whent the only person with the access to the file is you.

like image 85
Jakub Zaverka Avatar answered Sep 18 '22 10:09

Jakub Zaverka


A private method cannot be overridden because it is not visible to child classes.

like image 21
Paul Croarkin Avatar answered Sep 19 '22 10:09

Paul Croarkin