Forums Register Login

round up exam #25 urgent

+Pie Number of slices to send: Send
during the arithematic when the operands are of different types the resulting type is always the widest of the 2 types for which the answer was given as false
but i feel the answer is true cause if u add an int + float the result is always float.
the answer given was also not clear, but why was it given as false i feel the answer is true can anybody pls explain
+Pie Number of slices to send: Send
What about
short i = 3;
byte j = 4;
What's the result of
k = i+j
or
k = i*j
k can't be a short because i and j are automatically promoted to ints during the arithmatic operation - but an int is wider than the widest type of either variable (short).
So sometimes when the operands are of different types, they're automatically promoted to something other than the widest type. That's why it's false.
Hope this helps,
Kathy
Good heavens! What have you done! Here, try to fix it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 907 times.
Similar Threads
Question related to Garbage Collector
Ques. from JTips Mock 1
operators
javaranch game
unsigned right shift
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:38:12.