Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

A question about immutable object: Integer

807591Feb 22 2008 — edited Mar 5 2008
import java.lang.Integer;
public class ImmutableObject {

public void changeImmutable(Integer x){
x = x+1;
System.out.print(x );
}

public static void main(String[] args){
Integer x = new Integer(1);
ImmutableObject i= new ImmutableObject();
i.changeImmutable( x);
System.out.print( x);
}
}

Hello everyone,

Why the output of the program above is 21 rather than 22?
Is it because of +? Can anyone tell me about this?
Thanks a lot.

Kolapig
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 2 2008
Added on Feb 22 2008
19 comments
398 views