+ 2

How can i make a variable, a constant in java?

Java

13th Aug 2020, 7:28 AM
Chibundu Omoji
3 ответов
+ 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/
13th Aug 2020, 8:10 AM
Raina Dhankhar
Raina Dhankhar - avatar
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?
13th Aug 2020, 8:12 AM
Ipang
0
final
13th Aug 2020, 9:12 AM
Namit Jain
Namit Jain - avatar