• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

K and B Chapter 3 self test qn no 12

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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..

 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ba[0] and ba[1] both holds the reference b1 which has its size set as 4 in the go() method.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
read this small Story
 
kiruthigha rajan
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


yeah typing mistake...
thanks alot
 
Look! It's Leonardo da Vinci! And he brought a tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic