•One of the use of “final” keyword in Java is to declare constant variables.
•The value of constant variables cannot be changed once they are initialized.
•So, the final variables must be initialized when they are declared.
•final variables are allocated memory separately as the static variables.
•Each object does not have its own copy of the final variable.
•Syntax for declaring a final variable is as follows:
final data-type variable-name = value;
Example:
final int SIDES = 6;
•In Java final variables have a naming convention. All the final variables must be in uppercase. So, it will be easy do identify final or constant variables from the rest of the other variables.
•The value of constant variables cannot be changed once they are initialized.
•So, the final variables must be initialized when they are declared.
•final variables are allocated memory separately as the static variables.
•Each object does not have its own copy of the final variable.
•Syntax for declaring a final variable is as follows:
final data-type variable-name = value;
Example:
final int SIDES = 6;
•In Java final variables have a naming convention. All the final variables must be in uppercase. So, it will be easy do identify final or constant variables from the rest of the other variables.
No comments:
Post a Comment