• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock Exam from Bill Brogden

 
Maria Garcia
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What happens when a program calls the Result method with a value of 30 ? The answer is 30
Question:
Shouldn't it be 31 ?
 
sun par
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
X is passed on as N. After that X is a local variable and so any changes made in N does not reflect in X.
 
Maria Garcia
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm, i thought N and X were referring to the same object when it was passed to method Increment. I'm still confused.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We start out with one object pointed to by X. Next we pass that one object to a method. We now have one object pointed to by X and N. Next we create a brand new object and have N point to it.
Now we have two objects. One pointed to by N and another pointed to by X.
When we get back to the result() method, X is still pointing to the original object, not the new object that N was pointing to.
 
Maria Garcia
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sun, Thomas!
Now I get it!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yaknow, I do respond to reader email so you could have asked me.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic