This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
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 Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arithmetic Compound Assignment Operators.." Watch "Arithmetic Compound Assignment Operators.." New topic

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).

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 43350
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.
jQuery in Action, 3rd edition
subject: Arithmetic Compound Assignment Operators..
jQuery in Action, 3rd edition