santhosh.R gowda wrote:
char c= (char)(b); //(1)
System.out.println((int)c); //output: 65535
Can you please tell me how we get the out put 65535 i'm confused
Easy part, a byte is signed 8 bit value, and a char is a unsigned 16 bit value. Hard part, you need to understand how
Java stores negative numbers... see twos complement...
http://en.wikipedia.org/wiki/Two's_complement
Once you understand twos complement, and how a byte is sign extended when casting to a char, it should be straightforward. However, if you are still confused (after you get up to speed on twos complement), come back here, and elaborate what you don't understand.
Henry