aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K and B Chapter 3 self test qn no 12 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K and B Chapter 3 self test qn no 12" Watch "K and B Chapter 3 self test qn no 12" New topic
Author

K and B Chapter 3 self test qn no 12

kiruthigha rajan
Ranch Hand

Joined: Dec 29, 2011
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
Bartender

Joined: May 31, 2011
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

Joined: Jan 28, 2008
Posts: 5575

read this small Story
kiruthigha rajan
Ranch Hand

Joined: Dec 29, 2011
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..
thanks in advance
Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
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..
thanks in advance


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

Joined: Dec 29, 2011
Posts: 69
At line 16, "ma" contains 6,4 owing to the assignment in the previous step

yeah typing mistake...
thanks alot
 
Consider Paul's rocket mass heater.
 
subject: K and B Chapter 3 self test qn no 12