The correct answer is marked as correct for this question.
Question 5 tb584704.JaSE11PrgISG.be2.63
Which of the following can fill in the blank to have the code compile and run without error? (Choose all that apply.)
int numberReindeer = 9;
System.out.println( (_____________) numberReindeer);
F. None of the above
You Answered Correctly!
Since the number 9 is small, it can successfully fit into any of the numeric types, making options A, B, and C correct. Additionally, an int can be autoboxed into an Integer. Since this is an Object, option E is also correct.
The answer is silly (except for E), it isn't because the number is small, as this would work just fine too:
jshell> int numberReindeer = Integer.MAX_VALUE;
numberReindeer ==> 2147483647
Even further, primitive casting never generates "errors" or runtime exceptions, so calling the bit truncation "running with an error" is rather confusing to, well, at least me:
That is, are we calling the following executions errors for the exam?
They are defined behaviors I don't love but know to expect:
jshell> (short) numberReindeer
$6 ==> -1
jshell> (byte) numberReindeer
$7 ==> -1
jshell> (char) numberReindeer
$8 ==> '?'
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)