Conversion or Casting..........

Hi

I think i got a superb question.:)Let me explain u first.

Widening Conversion:::

A conversion that accommodate wider range of values than the original type.e.g.,

int in=25;

double d=in; //is legal

because int in is 32 bit and double d is 64 bit.

int > double

My Question:::

According to defination of Conversion , how it is possible to assign long value to float with out casting?

long lng=10;

float fl=lng;//it is legal. why?

because long is 64 bit and float is 32 bit.

Is there any Duke $ for a superb question. lmao :)

Thank you

[638 byte] By [sjafery] at [2007-9-26 10:36:33]
# 1

The explanation is this simple: because the "wideness" is measured by the range of values the type can represent, not how many bits the type takes.

This way the conversion from any integer type to any floating point type is always widening.

Also conversions from short to char and char to short are narrowing, even though both types are 16 bit. The range of short is from -2^15 to 2^15 - 1 and the range of char is from 0 to 2^16 - 1 so there are char values that can't be short and short values that can't be char.

jsalonen at 2007-7-1 23:02:13 > top of Java-index,Core,Core APIs...