final Variables
A final
variable, also called a “constant,” is a variable whose value you can’t change after it’s been initialized. For example, you might use a final
variable to define a constant value, such as pi. To declare a final
variable, you add the final
keyword to the variable declaration, like this:
static final int WEEKDAYS = 5;
Although it isn’t required, adding the static
keyword is common for final variables.
Get Java For Dummies Quick Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.