Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dans Question-casting

 
shetal bansal
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
float f=10L;
This is a valid declaration.
But how is it possible as float f is 32 bits and 10L is a long with size as 64 bits?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The conversion from long to float is "widening" in terms of range -- not bit size.

A 32-bit float has a much greater range than a 64-bit long, but this is because the float gives up precision. This has to do with the way in which floating-point values are typically stored in computers.

Here is an interesting thread on the topic...

http://www.coderanch.com/t/247234/java-programmer-SCJP/certification/method-parameter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic