Decoding “final” in java
When I was a beginner in Java(which I feel still I am), and was preparing for interviews, there comes a common question question often asked in an interview
What is the use of final in java ?
The answer used to be, we can use final in 3 different ways, First when we use final with a class, we can’t inherit that class. Second when we use final with a method, then we can’t override that method, lastly if used with variable it make sure that the variable is not modified once it’s instantiated.
This would not have been exactly as same but some what close to it.
Now that I am a little more experienced when I look back at this answer I think I can modify this answer and can make it more simple and elaborated,
If you have noticed using final with all the three , class, method and variable make them unchangeable, you can’t modify their behavior once they are defined and in case of variable instantiated.
So in simple words can’t we say, final key word is used to make behavior of class , method and variable non-modifiable.
By behavior I mean functionality.
Final is in it self a quite deep topic, In future I will try to cover more aspect of it.