I am not clear about the fact that a long could be implicitly converted to float. float only has 32 bits where as long has 64 bits. How is it possible??
The short answer is: Because it is. Those are the rules of the language. But they are not arbitrary. As a former so-called scientific programmer, I can say that sometimes the number of significant digits is more important than the absolute maximum and minimum values that a variable can posses. Meditate upon this and you shall get the answer
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD
A longer answer: a widening conversion like long to float can indeed involve a loss of precision that can be thought of as round-off error. The long value 1234567890123456789L gets rounded to 1.23456794E18F as a float, or 1.23456789012345677E18 as a double. This is within the possible error you always can have when using floats and doubles, so it should be expected. And it isn't nearly as bad as what can happen for narrowing conversions, when for example the double value 1.2345678901234567E200 gets converted to Float.POSITIVE_INFINITY as a float, 9223372036854775807L as a long, 2147483647 as an int, and -1 as a short or byte. The exact details of how this happens are beyond the scope of our discussion, but the point is - it's not pretty. Widening conversions can result in roundoff error; narrowing conversions can result in complete destruction of any significant digits in the answer - that's why it's treated differently, in most cases forcing the programmer to explicitly cast when narrowing is desired.