web analytics

Java Final Variables

In some cases we need to user variable as “constant” and do not want to change its value after initialization. We use final keyword for this purpose. following example shows declaration and initialization of a final variable.

final name = "John";

Now compiler will show a compile time error if we try to assign some other value in variable name because it has been declared as final