About Question enthuware.ocajp.i.v7.2.1154 :
Posted: Wed May 08, 2013 11:06 am
The explanation regarding the int,int answer says as follows
a*10/4.0; generates a double so, A2's m1() cannot return an int. ( It will need a cast otherwise: return (int) a*10/4.0; )
However, with this form of casting there still seems to be compilation error (cannot convert from double to int)
My understanding is that since the casting operator precedence is higher than that of * and / operators, thus it only concerns 'a' (which is already an int) and then there is int divided by double again
So I suppose it should be return (int) (a*10/4.0); with parentheses?
a*10/4.0; generates a double so, A2's m1() cannot return an int. ( It will need a cast otherwise: return (int) a*10/4.0; )
However, with this form of casting there still seems to be compilation error (cannot convert from double to int)
My understanding is that since the casting operator precedence is higher than that of * and / operators, thus it only concerns 'a' (which is already an int) and then there is int divided by double again
So I suppose it should be return (int) (a*10/4.0); with parentheses?