Hi Mateen,
Numeric promotion to the operands is applied using Identity
conversion or widening primitive conversion.
In our case it is widening conversion.
"The following conversions on primitive types are called the
widening primitive conversions :
byte to short, int, long, float, or double
short to int, long, float, or double
char to int, long, float, or double
int to long, float, or double
long to float or double
float to double "
Now the operand 'O' will be promoted to int (which is 48 unicode
value) as the other operand 7 is an integer.
The result of the expression 48 - 7 is 41.
Now JVM uses "Narrowing Primitive Conversion" as part of "Assignment Conversion" if all the below mentioned conditions
are met.
1. The expression is a constant expression of type int. (true, 48 is a constant of type int)
2. The type of the variable is byte, short, or char. (true, variable k is of type char)
3. The Value of the expression is representable in the type of the variable. (true, the constant 48 fits in 16 bits, size
of char is 16 bits)
Now in your example all the above mentioned conditions are met, and the conversion is error free. There is no need for explicit
conversion.
I will give you an example where you will need explicit
conversion.
For ex: the result of the expression is 65537
You will get a compile time error "possible loss of precision"
if you write
char k = 65537;
In this case you need explicit conversion i.e., char k = (char) 65537;
Refer 2.6 for more info at
http://java.sun.com/docs/books/vmspec/2nd-edition/html/Concepts.doc.html#16021