-
Notifications
You must be signed in to change notification settings - Fork 39
/
hashcode_equals.java File
44 lines (37 loc) · 1.02 KB
/
hashcode_equals.java File
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
package misc;
/**
* Note:-
* 1. equals(Object obj): a method provided by java.lang.Object that
* indicates whether some other object passed as an argument is "equal to" the
* current instance.
* 2. hashcode(): a method provided by java.lang.Object that
* returns an integer representation of the object memory address.
*
*/
public class Hashcode_Equals {
private int id;
private String name;
public Hashcode_Equals(int id, String name) {
this.name = name;
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static void main(String[] args) {
Hashcode_Equals obj1 = new Hashcode_Equals(1, "Alex");
Hashcode_Equals obj2 = new Hashcode_Equals(1, "Alex");
System.out.println("Alex1 hasCode(): " + obj1.hashCode());
System.out.println("Alex2 hasCode(): " + obj2.hashCode());
System.out.println("Checking equality: " + obj1.equals(obj2));
}
}