Reputation: 11
I am a first year computer science student. We just starded learning java. Our prof told us about the widening, but i did not understand something and maybe you can help me. When you do the following operation (double*int) + (char /-short ) – (float * byte) the answer will be double. But, the teacher also told us that the answer just for (char /-short ) will be float. Why float?
Thanks!
Upvotes: 1
Views: 72
Reputation: 198221
Your teacher is wrong. The result will be of type int
.
The exact rules are outlined in the Java Language Specification section 5.6.2, which indicates that both operands of the division will be widened to type int
before the division takes place, so the result will be an int
.
Upvotes: 2