Final Variables

A variable declared using keyword final is like constant variable in C/C++. Value
assigned once can not be changed later.
A final variable can be initialized either at declaration time or inside constructor
functions. No other method can modify its value. If any method try to modify the
value, then the compiler shows an error message.
A final variable must be initialized before its use because it does not take any
default value like other non-final instance variables.
A static variable can also be declared as final, for example, Thread.MAX_PRIORITY,
Thread.MIN_PRIORITY are static and final variables of java.lang.Thread class.

Method parameters can also be declared as final.

Final variables can be of two types:• final primitive variables.
• final reference variables.
The diff erence between them is that the value of final primitive variable
can not be changed once it has been initialized, whereas in case of final reference variable, its reference value can not be changed but the state of the object to
which it refers can be changed.
For Example:

17 Years experience in Training & Development.
Founder of realJavaOnline.com, loves coding in Java(J2SE, J2EE), C++,PHP, Python, AngularJS, Android. If you like tutorials and want to know more in depth about Java , buy his book "Real Java" available on amazon.in.
#Email :[email protected]#Contact : 98722-46056