posted 15 years ago
hi kamani,
"In java constant and final expressions are evaluated at compile time, however variable expressions are evaluated at run time".
In your code b2 is final i.e. compiler knows that its value is with in the range of char(0-65535) and that why line 6 wont cause any
problem.
Now, lets talk about
Its a variable expression(line 02.), and will be evaluated at run time, thats why compiler is not aware of this fact that b1 is also with in the
range of char. However it(compiler) just know one thing that b1 is byte, and that why gives compile time error as byte consist of
negative range also(-1 to -128) that can not be assigned to chars...
I hope you get my point...