+ 13

What is main difference in final and static variable?

12th Jun 2017, 1:11 PM
kulkarni swati
kulkarni swati - avatar
4 Answers
+ 1
in java you can write : public final static Double PI=3.14; to obtain a costant, it is static because is not a field of an instance but a value of the class. It's final because its value can't change after initialization. A costant should be ever static, if isn't, you waste a lot of memory to save in every instance of the class the same thing
17th Jun 2017, 9:37 PM
Federico Bachis
Federico Bachis - avatar
+ 12
Once it has been assigned, the value of the final variable cannot change. static means it belongs to the class not an instance, this means that there is only one copy of that variable/method shared between all instances of a particular Class.
12th Jun 2017, 1:27 PM
kulkarni swati
kulkarni swati - avatar
+ 3
final variable value is unchangeable while static variable value is.
12th Jun 2017, 1:23 PM
Loai Hazima
Loai Hazima - avatar
0
In Java Scrip you must write var: x=number;
2nd Feb 2018, 9:07 AM
Đ”Đ°ĐœĐžĐ»