aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes SCJP related ..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "SCJP related ....." Watch "SCJP related ....." New topic
Author

SCJP related .....

Prashant Kirtiwar
Greenhorn

Joined: Jul 08, 2005
Posts: 6
dear all....
see this code..

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
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
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.

Think about this code (Note: 10 is int):


SCJP 1.4 (100%) Done.<br />SCJD (URLyBird 1.2.3 Started)
 
Consider Paul's rocket mass heater.
 
subject: SCJP related .....