class A {
public static void main(String [] varun) {
byte b = 65;
char ch = b;
System.out.println(ch);
}
}
Why its give an error:
possible loss of precision
required char
found byte
The error text is misleading.
A char
is a 2 byte unsigned type (range 0 to 65535)
A byte
is a 1 byte signed type (range -128 to 127).
Therefore a byte
cannot be represented in a char
in full generality (as you'll lose the negatives). So you get an error; albeit a misleading one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With