-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEqualsDemo.java
More file actions
37 lines (29 loc) · 593 Bytes
/
EqualsDemo.java
File metadata and controls
37 lines (29 loc) · 593 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
package StringDemos;
class Employee {
int id;
String name;
Employee(int id, String name) {
this.id = id;
this.name = name;
}
@Override
public boolean equals(Object o) {
Employee e = (Employee) o;
if (this.id == e.id && this.name.equals(e.name)) {
return true;
} else {
return false;
}
}
}
public class EqualsDemo {
public static void main(String[] args) {
Employee ram1 = new Employee(1001, "Ram");
Employee ram2 = new Employee(1001, "Ram");
if (ram1.equals(ram2)) {
System.out.println("Same");
} else {
System.out.println("Not Same");
}
}
}