What is the final variable?
What is the final variable?
In Java, when final keyword is used with a variable of primitive data types (int, float, .. etc), value of the variable cannot be changed. For example following program gives error because i is final. final int i = 10 ; i = 30 ; // Error because i is final.
First of all, final is a non-access modifier applicable only to a variable, a method, or a class.
Following are different contexts where the final is used. Final variables.
When a variable is declared with a final keyword, its value can't be modified
Tally Prime |Download Tally Prime | Buy Tally Prime
A final variable can be explicitly initialized only once. A reference variable declared final can never be reassigned to refer to a different object. However, the data within the object can be changed.