my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Arithmetic Compound Assignment Operators.. 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 » Java » Beginning Java
Bookmark "Arithmetic Compound Assignment Operators.." Watch "Arithmetic Compound Assignment Operators.." New topic
Author

Arithmetic Compound Assignment Operators..

Phillipe Rodrigues
Ranch Hand

Joined: Oct 30, 2007
Posts: 165
Why i get output for the below program?

---------- Run ----------
Hello World!
Normal Termination
Output completed (0 sec consumed).





Thanks,
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38426
    
  23
To the Batmobile!

Oh no, that should be Java Language Specification, or anywhere where you can read that the compound operators can return their original type rather than going to int.

It is quite complicated; they can create an int and then return it to their original type, so your example will compile and run happily, but you can get some unexpected results if you use types "narrower" than int (short, byte, char). It is described lot better in the Java Language Specification page I showed you. "Complete abruptly" means to suffer an exception at runtime.
 
 
subject: Arithmetic Compound Assignment Operators..