function returning same value after pass by copy in java
<p>I have a code as below where I am swapping the <code>Instance variables</code> of class in <code>Function</code> called <code>SwapNames</code> </p>

<pre><code>public class Sam3 
{
    public String FirstName, LastName;

    public static void main(String[] args) 
    {   
        Sam3 objSam1 = new Sam3();
        Sam3 objSam2 = new Sam3();

        objSam1.FirstName = "Name1";
        objSam2.LastName  = "Name2";        

        System.out.print(objSam1.FirstName + " " + objSam2.LastName);

        SwapNames(objSam1, objSam2);

        System.out.print(objSam1.FirstName + " " + objSam2.LastName);
    }

    public static void SwapNames(Sam3 obj1, Sam3 obj2)
    {   
        Sam3 temp = obj2; 
        obj2 = obj1;
        obj1 = temp;

        obj1.FirstName = "First Name";
        obj2.LastName  = "Last Name";
    }
}
</code></pre>

<p>Now the Output of the Code is as below</p>

<pre><code>Name1 Name2
Name1 Name2
</code></pre>

<p>The thing which I dont understand is I swapped the values in <code>obj1 and obj2</code> - References made to their <code>classes</code>.After that I am changing the value.</p>

<p>Why the code is not taking effect.</p>

<p>Thanks for reply  </p>
