+ 1
how to declare a const in java ??
i don't find the const lesson in this tutorial
8 Answers
+ 3
put final in front of variable for example final int HELLO = 2;
+ 3
yes you can but kind of defeats the purpose of a constant you want to use constants for things like tax or a persons name so might as Well initialize right away but java lets you do whatever you want really lol
+ 2
it is good style to caps lock the final variable
+ 2
is that a question or a comment? lol
+ 1
final varType varName = varValue;
The keyword final does the trick.
Also check out enums, they can be useful for for example if you wanna check what day it is, with enum you could do Day.SUNDAY.
Try to keep them uppercase, and they are usually static.
0
if i declare a const not initialized (final int x;) i can put a value in this const after declare
0
question đ
0
ok, thank's