wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Primitive conversions 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 "Primitive conversions" Watch "Primitive conversions" New topic

Primitive conversions

lakshmi nair
Ranch Hand

Joined: Oct 11, 2000
Posts: 63
Hi all,
I'm new to this..
I had a doubt.
class LongTest{
void method(float fl) {
System.out.println("Method Float");
void method(double dl) {
System.out.println("Method Double");
public static void main(String[] args) {
long l = 45L;
LongTest f = new LongTest();
The above code outputs "Method Float". Long is of size 64 bits,Float, 32bits and double 64bits. I dont get how float is selected when what i understood is that in method calls the technique followed is Widening Conversions. Am i mistaken in this,anywhere ? Please help...
Arpitha Reddy

Joined: Oct 04, 2000
Posts: 20
It appears that the type is being promoted to the next higher type..in this case from long to float. If you had a similar method on long and called it with an int, it would probably result in the 'long'.
Anna s Iyer

Joined: Aug 21, 2000
Posts: 24
Here is the order in which widening conversion takes place.
byte to short, int, long, float, or double
short to int, long, float, or double
char to int, long, float, or double
int to long, float, or double
long to float or double
float to double

In your case long is first looks for float and if not goes to double.
Hope this helps,
Anna S Iyer.
lakshmi nair
Ranch Hand

Joined: Oct 11, 2000
Posts: 63
Thanks Arpitha and Anna..
So that means it has practically nothing to do with the sizes,32 and 64...
I agree. Here's the link: http://aspose.com/file-tools
subject: Primitive conversions
It's not a secret anymore!