Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

round up exam #25 urgent

 
ravi ckumar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kathy Rogers
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic