File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes assignment question?? doubt? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "assignment question?? doubt?" Watch "assignment question?? doubt?" New topic
Author

assignment question?? doubt?

srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
float a = 1; // 1
float b = 1L; // 2
float c = 1F; //3
float d = 1.0; //4

hi,
4 wouldnt compile as ur trying to assign an double value to a float...

byte b3 = 1; // 5
byte b4 = 1L; // 6
byte b5 = 1.0; // 7
byte b6 = 1.0d; // 8

what i feel after seeing these expressions is ..
uptil int if its a constant it can assign to any value....as far as it is in the range of the left hand operand...
but after that for long ,float,double it sees whether they can assignable to appropriate primitive...

i got this doubt coz line 6 7 8 generate compile error,i thought they are compile time constants so they cub be easily fit into it...

please clarify


Thanks & Regards<br /> <br />-Srikanth
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5300
    
  13

about this line float d = 1.0; //4
you said yourself: "4 wouldnt compile as ur trying to assign an double value to a float..."

what's the difference between that line and following 2 lines (except for the left thing being a byte instead of a float)
byte b5 = 1.0; // 7
byte b6 = 1.0d; // 8

indeed, there is no difference.

for line 6 you're telling the compiler you are using a long and so you try assigning a long to a byte, which also don't work without using explicit cast


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
GeeCON Prague 2014
 
subject: assignment question?? doubt?