Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. package com.sid.practice;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. public class InputOutputPractice {
  7.  
  8. public InputOutputPractice() {
  9.  
  10. }
  11.  
  12. public static void main(String[] args) {
  13. Employee e = new InputOutputPractice().new Employee(1, "e");
  14. Employee e1 = new InputOutputPractice().new Employee(2, "e1");
  15. Employee e2 = new InputOutputPractice().new Employee(1, "e2");
  16.  
  17. Map m = new HashMap();
  18. m.put(e, "e");
  19. m.put(e1, "e1");
  20. m.put(e2, "e2");
  21. System.out.println(m);
  22.  
  23. }
  24.  
  25. class Employee
  26. {
  27. public Employee(int id, String name){
  28. this.id=id;
  29. this.name = name;
  30. }
  31. private int id;
  32. private String name;
  33. public String getName() {
  34. return name;
  35. }
  36. public void setName(String name) {
  37. this.name = name;
  38. }
  39. public int getId() {
  40. return id;
  41. }
  42. public void setId(int id) {
  43. this.id = id;
  44. }
  45. @Override
  46. public boolean equals(Object obj) {
  47. return ((Employee)obj).getId()==(this.getId());
  48. }
  49. @Override
  50. public int hashCode() {
  51. return Integer.valueOf(getId()).hashCode();
  52. }
  53.  
  54. @Override
  55. public String toString() {
  56. // TODO Auto-generated method stub
  57. return this.id + "--" + this.name;
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement