• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Float Declaration

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raef,

if you haven't confused Float and float, then the study guide is wrong.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
What are your superhero powers? Go ahead and try them on this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic