why the Employee class{} equals method return false

  Oct 15, 2016

class Employee { public Employee(int Salary) { System.out.println("Employee Salary " + Salary); }

public static void main(String args[])
{
    Employee e1 = new Employee(20000);  
    Float s1=new Float(12f);


            Employee e2 = new Employee(20000);  
    Float s2=new Float(12f);    

      // equal and hashcode method for Employee class //
            System.out.println("Are e1 and e2 equal: " + e1.equals(e2));  
            System.out.println("e1 hashCode: "+e1.hashCode()+" e2 hashCode()"+e2.hashCode());  

    // equal and hashcode method for Float class //
              System.out.println("Are s1 and s2 equal: " + s1.equals(s2));  
                       System.out.println("s1 hashCode: "+s1.hashCode()+" s2 hashCode()"+s2.hashCode()); 

} }

In Progress 0
equals() method equals() method and hashcode() method. 8 months ago 0 Answer 0 views

Answers ( 0 )

Your Answer