-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
49 lines (43 loc) · 948 Bytes
/
Employee.java
File metadata and controls
49 lines (43 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
public class Employee
{
private int regno;
private String name;
//constructor of Employee class
public Employee(int regno, String name)
{
this.name = name;
this.regno = regno;
}
public int getRegno()
{
return regno;
}
public void setRegno(int Regno)
{
this.regno = regno;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
HashCodeExample.java
public class HashcodeExample
{
public static void main(String[] args)
{
//creating two instances of the Employee class
Employee emp1 = new Employee(918, "Maria");
Employee emp2 = new Employee(918, "Maria");
//invoking hashCode() method
int a=emp1.hashCode();
int b=emp2.hashCode();
System.out.println("hashcode of emp1 = " + a);
System.out.println("hashcode of emp2 = " + b);
System.out.println("Comparing objects emp1 and emp2 = " + emp1.equals(emp2));
}
}