Hi,
I am a beginner to programming. I am currently preparing for SCJP 6 when I came across this code on final variables. Can anybody just help me out with this?
final int a = 1;
final int b;
b = 2;
int x = 0;
switch (x) {
case a: // OK
case b: // compiler error
When I tried this code, I got a compile error like this:
constant expression required for case b:
My doubt is if final variables can be initialized anytime(not necessarily at the time of the declaration of the variable), then why am I getting this error for variable b?
Thanks in advance.