calling a private method by a return statement java
<p>So I'm new to java and I'm trying to wrap my head around this. So far I'm writing a public method that calls a private method, both of which are written in the same class. When testing the public method, I am able to call the public method against an object, employeeOne, whose parameters are supplied by the user. I'm not exactly sure whats going on with the private method call here though since it appears that I'm calling it on the class (i think) and not the objects with defined attributes. </p>

<p>So here is a private method that I have written inside a class called Employee:</p>

<pre><code>private static double computeGrossPay()
{
    if (hoursWorked &lt;= 40)
    {
        grossPay = (hoursWorked * payRate);
    }
    else if (hoursWorked &gt;= 40)
    {
        grossPay = ((40 * payRate) + ((1.5 * payRate) * (hoursWorked - 40)));
    }
    return grossPay;
}
</code></pre>

<p>I was trying to figure out a way to call this method in another class and obviously since it is a private method I can't call it anywhere outside of the class it is written in. So I wrote a public method that makes a call to the private method</p>

<pre><code>public double grossPayDisplay()
{
    return Employee.computeGrossPay();
}
</code></pre>

<p>This is where my question comes into play: So far this code works but I'm not entirely clear on <em>why</em> it works.</p>

<p>Here is how I tested it:</p>

<pre><code>System.out.println(employeeOne.grossPayDisplay());
</code></pre>

<p>employeeOne is an object created from the class Employee whose parameters are supplied by the user, my question is:</p>

<p>How does the compiler go from Employee in Employee.computeGrossPay() to employeeOne? </p>

<p>Or to reiterate how does  </p>

<pre><code>return Employee.computeGrossPay() 
</code></pre>

<p>actually pass attributes to computeGrossPay()? </p>
