Pass by value in Java
<p>I am new to java and I am currently trying to learn how pass by value works. I have a main class called Test and a second class called TestMax. What I am trying to achieve in my code below is to set the value in the main class for the 2 parameters i and j from class TestMax and call the method <code>max()</code> by passing the values of the parameters which I have just passed previously.</p>

<p>The output to console should be something like this: </p>

<pre><code>The maximum between 2 and 10 is 10.
</code></pre>

<p>I know the there is something wrong with the way I pass the values to the method <code>(int res = max(i,j)</code> but I spent the last 2h to figure out how why this is not working and I can't figure that out.</p>

<pre><code>package testproject;
public class Test {
    /** Main method */
    public static void main(String[] args) {
        TestMax pass = new TestMax();
        pass.setI(2);
        pass.setJ(10);
        int res = max(i,j);
        System.out.println("The maximum between " + pass.getI() +
                " and " + pass.getJ() + " is " + res);
    }
}
</code></pre>

<p><strong>Second class TestMax:</strong></p>

<pre><code>package testproject;

public class TestMax {

    int i ;
    int j ;

public static int max(int num1, int num2) {

    int result;
    if (num1 &gt; num2)
       result = num1;
    else
       result = num2;

    return result;

}

//Getters &amp; Setters
public void setJ(int j) {
    this.j = j;
}

public int getJ() {
    return j;
}

public void setI(int i) {
    this.i = i;
}

public int getI() {
    return i;
}
</code></pre>
