public class seeit { byte getNo(byte x,double y) { return (short) ((byte)4/2.0 * 2) ; } public static void main(String as[]){ seeit st = new seeit(); st.getNo((byte)12,22); } }
It is going to work.compile and run successfully ..alright..but now see the real scenario I changed a little bit code....
public class seeit { byte getNo(byte x,double y) { return (short) (x/y * 2) ; } public static void main(String as[]){ seeit st = new seeit(); st.getNo((byte)12,22); //System.out.println(i); } }
I GOT AN COMPILE ERROR INDICATING POSSIBLE LOSS OF PRECISION.... Why do I get this error as the program remain the same as the before one??? Pls remove my query....
regards Prashant...
Debashree Halder
Ranch Hand
Joined: Jul 27, 2005
Posts: 81
posted
0
Because it cannot convert from 'short' (16 bit) to 'byte'(8 bit)
-Debashree
Debashree Halder<br />SCJP 1.5<br />Washington DC
Georgy Bolyuba
Ranch Hand
Joined: Feb 18, 2005
Posts: 162
posted
0
Originally posted by Prashant Kirtiwar:
return (short) ((byte)4/2.0 * 2) ;
return (short) (x/y * 2) ;
Please, use [ CODE] [ /CODE] (without spaces).
The difference is that in first case you using literal constant and in second case not.