final variables in Java
In Java, we can use final keyword with variables, methods, and classes. When the final keyword is used with a variable of primitive data types such as int, float, etc), the value of the variable cannot be changed.
Example 1: Usage of final with primitive datatype
Now you must be wondering what if we do use final keyword non-primitive variables, let us explore the same as we did above with the help of an example.
Note: Non-primitive variables are always references to objects in Java, the members of the referred object can be changed. final for non-primitive variables just means that they cannot be changed to refer to any other object.
Example 2: Usage of final with primitive datatype
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.