This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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: 37950
    
  22
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..
 
Similar Threads
about ?: operator
Matching words except those in tags with regex
SCJP 5: Mock questions
format method
problem related to floats