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?
About Question enthuware.ocajp.i.v7.2.1154 :
Moderators: Site Manager, fjwalraven
-
- Posts: 33
- Joined: Mon May 06, 2013 9:41 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1154 :
You are right. This has now been fixed. Thank you for your feedback!
Paul.
Paul.
Who is online
Users browsing this forum: No registered users and 22 guests