QUESTION IMAGE
Question
which of the following assignment statements is illegal? a short s = 10; b float f = -34; c int t = 23; d int t = 4.5;
Brief Explanations
- Option A: Assigning an integer literal (10) to a
shortvariable is legal as 10 is within the range ofshort(usually -32768 to 32767). - Option B: Assigning an integer literal (-34) to a
floatvariable is legal because Java (or similar languages) allows implicit widening frominttofloat. - Option C: Assigning an integer literal (23) to an
intvariable is legal. - Option D: Assigning a floating - point literal (4.5) to an
intvariable is illegal. In languages like Java, you can't implicitly convert afloat(ordouble) to anintwithout a cast, as it would involve a loss of precision (the decimal part).
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
D. int t = 4.5;