Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!

# K and B Chapter 3 self test qn no 12

kiruthigha rajan
Ranch Hand
Posts: 69

What is the result?
A. 4 4
B. 5 4
C. 6 4
D. 4 5
E. 5 5
F. Compilation fails

can anyone explain how the answer is A.im confused with values passed here..

John Jai
Rancher
Posts: 1776
ba[0] and ba[1] both holds the reference b1 which has its size set as 4 in the go() method.

Seetharaman Venkatasamy
Ranch Hand
Posts: 5575

kiruthigha rajan
Ranch Hand
Posts: 69
John Jai wrote:ba[0] and ba[1] both holds the reference b1 which has its size set as 4 in the go() method.

When Box[] ba = go(b1, new Box(6)); reaches the go method the value contained is 5 and 6
then b1.size becomes 4,and b2 remains 6
this is placed in an array ma wer b2,b1 contains 6,5
then ma and ba shares the same array object.
here ba[0] is assigned to b1 which is 4
so this prints 4,4
am i right??
correct me if i am wrong..

Praveen Kumar M K
Ranch Hand
Posts: 256
kiruthigha rajan wrote:
John Jai wrote:ba[0] and ba[1] both holds the reference b1 which has its size set as 4 in the go() method.

When Box[] ba = go(b1, new Box(6)); reaches the go method the value contained is 5 and 6
then b1.size becomes 4,and b2 remains 6
this is placed in an array ma wer b2,b1 contains 6,5
then ma and ba shares the same array object.
here ba[0] is assigned to b1 which is 4
so this prints 4,4
am i right??
correct me if i am wrong..

At line 16, "ma" contains 6,4 owing to the assignment in the previous step.

kiruthigha rajan
Ranch Hand
Posts: 69
At line 16, "ma" contains 6,4 owing to the assignment in the previous step

yeah typing mistake...
thanks alot