How to pass by reference in Java
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/40480/is-java-pass-by-reference">Is Java pass by reference?</a>  </p>
</blockquote>



<p>This Java code:</p>

<pre><code>public class XYZ {   
    public static void main(){  
        int toyNumber = 5;   
        XYZ temp = new XYZ();  
        temp.play(toyNumber);  
        System.out.println("Toy number in main " + toyNumber);  
    }

    void play(int toyNumber){  
        System.out.println("Toy number in play " + toyNumber);   
        toyNumber++;  
        System.out.println("Toy number in play after increement " + toyNumber);   
    }   
}  
</code></pre>

<p>will output this:</p>

<pre> 
Toy number in play 5  
Toy number in play after increement 6  
Toy number in main 5  
</pre>

<p>In C++ I can pass the <code>toyNumbe</code>r variable as pass by reference to avoid shadowing i.e. creating a copy of the same variable as below:</p>

<pre><code>void main(){  
    int toyNumber = 5;  
    play(toyNumber);  
    cout &lt;&lt; "Toy number in main " &lt;&lt; toyNumber &lt;&lt; endl;  
}

void play(int &amp;toyNumber){  
    cout &lt;&lt; "Toy number in play " &lt;&lt; toyNumber &lt;&lt; endl;   
    toyNumber++;  
    cout &lt;&lt; "Toy number in play after increement " &lt;&lt; toyNumber &lt;&lt; endl;   
} 
</code></pre>

<p>and the C++ output will be this:</p>

<pre>
Toy number in play 5  
Toy number in play after increement 6  
Toy number in main 6  
</pre>

<p>My question is - What's the equivalent code in Java to get the same output as the C++ code?</p>
