rahul,
b = -97 is a negative number. So, it is stored in its two's complement form - 1111 1111 1001 1111.
Since char is an unsigned integer, this number is assigned as a positive integer to the char variable cd. So, this value is 65439. Since most of the machines don't support unicode characters, they display '?' for displaying characters which are not in the ascii range.
When you assign the char variable to int variable id, this value 65439 is assigned. And that gets printed.
Hope this helps,
Regards,
Suresh.
Originally posted by rahul_mkar:
hi
byte b= -97;
char cd=(char)b;
System.out.println(" " +cd);
// prints ?
int id=cd;
System.out.println(" " +id);
// prints 65439
can anybody tellme what's going on and why