hello everyone,
Output is coming not equal for same input.what is the error in this program?
import java.util.*;
class newobj_equal
{
public static void main(String[] args)
{
int eid;
String ename;
double salary;
Scanner sin=new Scanner(System.in);
System.out.println("Enter eid");z
eid=sin.nextInt();
System.out.println("Enter ename");
ename=sin.next();
System.out.println("Enter salary");
salary=sin.nextDouble();
emp e1=new emp();
e1.accept(eid,ename,salary);
e1.display();
System.out.println("Enter eid");
eid=sin.nextInt();
System.out.println("Enter ename");
ename=sin.next();
System.out.println("Enter salary");
salary=sin.nextDouble();
emp e2=new emp();
e2.accept(eid,ename,salary);
e2.display();
if(e1.equals(e2))
System.out.println("Both equal");
else
System.out.println("Both not equal");
}
};
class emp
{
int eid;
String ename;
double salary;
public void accept(int eid,String ename,double salary)
{
this.eid=eid;
this.ename=ename;
this.salary=salary;
}
public void display()
{
System.out.println("Employee details is:");
System.out.println("\nEmp id="+eid+"\nEmp name="+ename+"\nEmp salary="+salary);
}
public boolean equals(Object obj)
{
if(obj instanceof emp)
{
emp o=(emp)obj;
return(eid==o.eid && ename==o.ename && salary==o.salary);
}
else
return false;
}
};