In a study guide, I came across the following question:- Which three are valid declarations of a float? (Choose Three) A.Float foo= -1; B.Float foo = 1.0 C.Float foo = 42e1; D.Float foo = 2.02f; E.Float foo = 3.03d; F.Float foo = 0x0123; Answer: A, D, F
However, Float foo=-1, gave incompatible types error. And Float foo= 0x123, also gave the same error. And only D turned out to be correct. Is there something I am missing?
Originally posted by Manfred Klug: ...if you haven't confused Float and float...
I think that's what's happening here. If these variables are declared as type Float (the wrapper object with an uppercase 'F'), then only D will work with autoboxing. But if they're declared as type float (the primitive with a lowercase 'f'), then A, D, and F will work as widening conversions.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
What are your superhero powers? Go ahead and try them on this tiny ad: