HashSample.java 602 B

1234567891011121314151617181920212223
  1. // Java program to demonstrates hashcode()
  2. // value for different objects
  3. class HashSample {
  4. int id;
  5. String name;
  6. public HashSample(int id, String name)
  7. {
  8. this.id = id;
  9. this.name = name;
  10. }
  11. public static void main(String[] args)
  12. {
  13. HashSample obj1 = new HashSample(1, "John");
  14. HashSample obj2 = new HashSample(1, "John");
  15. System.out.println("hashCode of obj1: "
  16. + obj1.hashCode());
  17. System.out.println("hashCode of obj2: "
  18. + obj2.hashCode());
  19. }
  20. }