This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
case expressions must be constant expressions , and in given code b is blank final variable , sa at compile time compiler checks the constant expression for case statement, and b get value 2 at run time
There is a difference between 'a' and 'b'. 'a' is initialized with a compile-time constant expression and is final. So we call it 'a constant variable'. 'b' is final but it is blank final variable. A blank final is a final variable whose declaration lacks an initializer.
That's why you cannot use 'b' in the way you are trying to use it.