Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Whiz Lab Sample Question

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Double d=Double.valueOf(120D);    //1  Compiles Successfully)

Float f=Float.valueOf(120D);       //2
Long a=Long.valueOf(120D);                       //3
Integer b=Integer.valueOf(120D);
    //4             // But not 2,3&4.

Could someone explain to me, clearly?
Why 2,3 & 4 are giving a compilation error but 1 doesn't?
Thanks for your help, in advance.
 
Ranch Hand
Posts: 42
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because only double can have double value ...which is correct.

Float ,Integer and Long can’t have double value .....which is bigger value for all .

Conversion of bigger value to smaller value needs casting.
 
Shweta Priyadarshi
Ranch Hand
Posts: 42
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the case of wrapper object so either they can consider their own value or in string form . But yes float can take float,into and double.
 
R Karthik
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your quick response.
 
Shweta Priyadarshi
Ranch Hand
Posts: 42
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ramya Natarajan wrote:Thanks for your quick response.



Welcome ramya😊
 
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic