Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing Object reference to method

 
shweta patiljadhav
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hav a doubt from
Mala Gupta's
book.

Suppose you have the following
definition of class Person:


what is the output of this code?




this is about referencing and output is John:Paul both times.

Please explain me how? it is been explained in book, I read it thrice, but bit worried that if this type of question comes in exam I will have to think a lot about such type of question ...if my concept is clear I will think else i won't.

Thanks,
Shweta
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shweta patiljadhav wrote:Please explain me how? it is been explained in book, I read it thrice, but bit worried that if this type of question comes in exam I will have to think a lot about such type of question ...if my concept is clear I will think else i won't.

Did you already have read this excellent article about pass-by-value? If you didn't, definitely do! And even 2, 3 or maybe 4 times until you completely understand how the mechanism works. I can't explain it better than in this article. Besides that article you'll find plenty of excellent topics (with great explanations and a bunch of code snippets) about passing object references to a method:
  • Why NullPointerException
  • Pass by value or reference, question from K&B mock test
  • change array values
  • Pass by Reference

  • If you have read the article and all these topics, and you still have questions and/or doubts, please let us know by clicking the "Post Reply" button

    Hope it helps!
    Kind regards,
    Roel
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic