Home >Java >javaTutorial >final variable in java
#Final variables can only be explicitly initialized once. A reference variable declared as Final can never be reassigned to reference a different object.
However, the data within the object can be changed. Therefore, the state of the object can change, but the reference cannot.
For variables, the final modifier is usually used with static to make the constant a class variable.
public class Test { final int value = 10; // The following are examples of declaring constants: public static final int BOXWIDTH = 6; static final String TITLE = "Manager"; public void changeValue() { value = 12; // will give an error } }
The above is the detailed content of final variable in java. For more information, please follow other related articles on the PHP Chinese website!