I have my head stuck in the SCJP 6 Study guide, and am confused about a point they make here.
Regarding casting ints to chars, they say that the following are perfectly legal, but you get a loss of precision (which I can totally understand):
char d = (char)-98;
char c = (char)70000;
System.out.println("d = " + d + " c = " + c);
The result of this is:
d = ? c = ?
The point here that I am confused on is that the resultant char value is printing out as just a question mark in both cases. I would have expected a nonsensical numeric value, possibly bearing little or no relation at all to the original value, but nevertheless numeric.
Why is the result a question mark? I don’t understand how just a question mark is a “loss of precision” here?
I have looked at many char related questions here on SO, and also googled a lot, but can’t find an answer to this.
Does it differ with other JVM’s? Or is it the standard response to all out-of-range char casts?
When you append a char to a String, the char is appended (‘a’ for example), and not its numeric value (97 for example). If you want to know what the numeric value of the char is, use