+ 1

What is the difference between "private" and "final" keywords in JAVA?

Along with that is there any way to change the value of final variables?

19th Nov 2019, 1:26 PM
Vishnu Vardhan S
Vishnu Vardhan S - avatar
4 odpowiedzi
+ 4
The final keyword is used to declare a variable constant. It cannot change its value throughout the program. Whereas private members of a class have access only within the class in which they are declared. Also remember a class cannot be private but it can be final.
19th Nov 2019, 1:36 PM
Avinesh
Avinesh - avatar
+ 2
Avinesh only top level class that cannot be private but inner class can
19th Nov 2019, 2:17 PM
Taste
Taste - avatar
+ 1
To add further detail to the good answer, final fields can be temporarily stripped of the modifier and changed via the reflection API (just a fun fact, not useful at all regularly :)). Further, final classes are classes which can't be inherited from (cannot be a base class).
19th Nov 2019, 2:36 PM
LunarCoffee
LunarCoffee - avatar
0
Taste Thanks, I knew that but didn't wanted to mention since it was a generic answer. What you said also applies for static classes. Anyways👍
19th Nov 2019, 2:23 PM
Avinesh
Avinesh - avatar