Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sid.practice;
- import java.util.HashMap;
- import java.util.Map;
- public class InputOutputPractice {
- public InputOutputPractice() {
- }
- public static void main(String[] args) {
- Employee e = new InputOutputPractice().new Employee(1, "e");
- Employee e1 = new InputOutputPractice().new Employee(2, "e1");
- Employee e2 = new InputOutputPractice().new Employee(1, "e2");
- Map m = new HashMap();
- m.put(e, "e");
- m.put(e1, "e1");
- m.put(e2, "e2");
- System.out.println(m);
- }
- class Employee
- {
- public Employee(int id, String name){
- this.id=id;
- this.name = name;
- }
- private int id;
- private String name;
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- @Override
- public boolean equals(Object obj) {
- return ((Employee)obj).getId()==(this.getId());
- }
- @Override
- public int hashCode() {
- return Integer.valueOf(getId()).hashCode();
- }
- @Override
- public String toString() {
- // TODO Auto-generated method stub
- return this.id + "--" + this.name;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement