This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Passing arguments to method 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 "Passing arguments to method" Watch "Passing arguments to method" New topic

Passing arguments to method

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi everyone,
I thought the answer is sb1 is "HelloThere"; sb2 is "HelloThere",but is wrong.
Could anyone kindly explain to me.
Thanks a lot.

[I added UBB CODE tags to your source code to make it more readable. Please try to use them in the future - Ajith]

Answer is: sb1 is "HelloThere"; sb2 is "Hello".

[This message has been edited by Ajith Kallambella (edited September 05, 2000).]
Shankar G

Joined: Sep 24, 2000
Posts: 16
This question has been already asked & answered, within in the past week -- plz. refer to the previous questions.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
When a method is called with parameters, the parameters is the copy of the real parameters. In the test, the refrence s1 and reference s2 is the copy of sb1 and sb2. Doublelessly, the first object is appended which is referenced by s1 and also by sb1. Though s2 is assigned with s1 in the method, the s2 really referencing the first object which appended, the sb2 still referencing the second object which has not been updated.
Did i expain it clear?
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks very much Shankar and Yiqing. I got it.
Have you checked out Aspose?
subject: Passing arguments to method
It's not a secret anymore!