wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on primitive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on primitive" Watch "Question on primitive" New topic
Author

Question on primitive

Thiyagarajan Kamala
Ranch Hand

Joined: Mar 16, 2003
Posts: 30
short s1=6;
s1+=20000;

if I rewrite this to
short s1=6;
s1=s1+20000;

Compile complains ...Can someone explain?.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
This will work...


The problem is that without the cast you try to assign an int to a short, which will make the compiler choke.

Using the short assignment (+=) I think the compiler does that for you, but I'm not 100% sure.


JDBCSupport - An easy to use, light-weight JDBC framework -
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Read this...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Thiyagarajan Kamala
Ranch Hand

Joined: Mar 16, 2003
Posts: 30
Thanks Ankit.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Sebastian was also right, so thanks to him too ...
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Ankit Garg wrote:Sebastian was also right, so thanks to him too ...


sweet
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Sebastian Janisch wrote:sweet


Sugar .......... Ooops, I forgot this is not the word-association thread
Thiyagarajan Kamala
Ranch Hand

Joined: Mar 16, 2003
Posts: 30
my bad ...Thanks to both of you...If i get this question in exam I will remember both of you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on primitive