• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

stringbuffers eg from overalltesting.com

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


I answered 4, but the correct choice is 2. In the statement in the code aboce, we have y=x. ie all tht is in x, ie AB is stored in B. Also objects are passed by the reference. so the original object gets affected. Hence, i answered 4. please correct me.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe this exact question was discussed here recently. Basically what it comes down to is, when you pass a reference into a function, it is actually sending in a COPY of that reference. So there are two unique references pointing to the same thing.

Thus, when you pass a and b into this function, the x.append actually changes A, because a and x are both pointing to the same thing. b remains unchanged because all the function is doing is taking the reference y (which pointed to the same thing that b points to) and points it to x. This causes no change in what b itself points to.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic