Skip to main content

Constants

info

Constants is a special variable whose value can't be modified during the program execution. Constant is also called as final variable.

Synthax:

[modifier] final <data Type> <variableName> = <value>;

Example:

final int a=99;
final String str1="Hello World";
final double d=99.99;

A variable that is declared as final and not initialized is called blank final variable.

Synthax:

[modifier] final <data Type> <variableName>;
<variableName> = <value>;

Example:

final int a;
a=99;

If the variable is declared as final and initialized in the next statement, then in the class file, compiler will replace that variable with the actual value.