| 1234567891011121314151617181920212223 |
- // Java program to demonstrates hashcode()
- // value for different objects
- class HashSample {
- int id;
- String name;
- public HashSample(int id, String name)
- {
- this.id = id;
- this.name = name;
- }
- public static void main(String[] args)
- {
- HashSample obj1 = new HashSample(1, "John");
- HashSample obj2 = new HashSample(1, "John");
- System.out.println("hashCode of obj1: "
- + obj1.hashCode());
- System.out.println("hashCode of obj2: "
- + obj2.hashCode());
- }
- }
|