Override the equals method
<p>I'm currently revising for an exam. On a past paper there was the question, </p>

<p>Override the equals method in the following class. The method shall check for
content equality of the whole state.</p>

<pre><code> class Employee
    {
        String firstName;
        int age;
    } 
</code></pre>

<p>[2 marks]</p>

<p>I did some fiddling for the right answer and have come up so far with this. Is there a simpler way to answer the question and is this right? Many thanks for help.  </p>

<pre><code> public class Employee
    {

     int age;

    public boolean equals(Object obj)
    {
        if(this == obj)
            {
                return true; //Reference equality.
            }    
        if(!(obj instanceof Employee)) 
            {
                return false; // not the same type.
            }
        Employee other = (Employee) obj;
        return firstName == other.firstName;
        return age == other.age;
        }
    }
</code></pre>
