2019-1-19 object祖宗类的equals重写

 1 package com.test;
 2 /**
 3  * object祖宗类的equals重写
 4  * @author Mr.kemi
 5  *2019-1-19
 6  */
 7 public class Equals {
 8     private int age;
 9     private String name;
10     
11     public int getAge() {
12         return age;
13     }
14     public void setAge(int age) {
15         this.age = age;
16     }
17     public String getName() {
18         return name;
19     }
20     public void setName(String name) {
21         this.name = name;
22     }
23     
24     public boolean equals(Object obj) {
25         if(obj instanceof Equals) {
26             Equals uobj = (Equals)obj;
27             if(uobj.getAge()==this.getAge()&&uobj.getName().equals(this.getName())) {
28                 return true;
29             }
30         }
31         return false;
32     }
33 }

 

posted @ 2019-01-21 13:34  kemihaha  阅读(115)  评论(0编辑  收藏  举报