Can someone help me? I was thinking the answer is 6 but correct answer is 5.
You have to remember that Integer objects are not mutable. So, for the increment to work, the value needs to be unboxed, incremented, and boxed again. The unboxing and boxing, changes the object that y references. It is no longer referencing the same object as x.
The x reference is still referring to the previous object -- which has the value of 5.
Henry