enthuware.ocajp.i.v7.2.1027

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Antenne88
Posts: 3
Joined: Sat Jul 13, 2013 2:49 pm
Contact:

enthuware.ocajp.i.v7.2.1027

Post by Antenne88 »

Hi,

I don't understand this explanation.

1. Where has x been assigned a new Integer object with the value of 6?
2. Why does x have the value of 5 when it's printed and the explanation tells me it's containing 6?

Wrapper objects are always immutable. Therefore, when dataWrapper is passed into wiggler() method, it is never changed even when x++; is executed. However, x, which was pointing to the same object as dataWrapper, is assigned a new Integer object (different from dataWrapper) containing 6.

Any help would be very much appreciated :roll:

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: enthuware.ocajp.i.v7.2.1027

Post by admin »

1. When you do x++;
This is same as doing x = x + 1;
So the original object that was passed was not changed but a new object containing 6 is created and assigned back to x. 'x' is a reference. x changes but not the object that was originally pointed to by it.

2. Where do you see x printed as 5? It prints 6 for x.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

qazwsx922
Posts: 7
Joined: Sat Sep 04, 2021 8:17 pm
Contact:

Re: enthuware.ocajp.i.v7.2.1027

Post by qazwsx922 »

it is never changed even when x++; is executed. However, x, which was pointing to the same object as dataWrapper, is assigned a new Integer object (different from dataWrapper)
then when such operators, ++ and -- are used,
in this questions, x++
always new object is created and assign updated value to it and also point to the newly created object instead of original(old) one?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: enthuware.ocajp.i.v7.2.1027

Post by admin »

Yes, when x is a reference to primitive wrapper. Not when x is a primitive.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 35 guests