+ 2
How can i make a variable, a constant in java?
Java
3 Respuestas
+ 9
What is the final variable in Java?
When we are using the final keyword with variable it means we are declaring a constant. In java, final variables are just like constants. If you want to make any constant variable, then use the final keyword with the variable.
1. If you are using a final keyword with primitive types of the variable (int, float, char, etc) then you can’t change the value of a final variable once it is initialized. So, we should initialize it.
2. If you are using a final keyword with non-primitive variables (By means of non-primitive variables are always references to objects in Java), the member of the object can be changed. It means we can change the properties of the object, but we can’t change to refer to any other object. We will discuss it separately in a final reference variable.
For more details: https://javagoal.com/java-final-variable/
0
A variable is variable, and a constant is constant. What did you mean by "make a variable, a constant" anyways? do you understand they are different one from the other?
0
final