-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDog.java
More file actions
48 lines (46 loc) · 865 Bytes
/
Dog.java
File metadata and controls
48 lines (46 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public class Dog implements Pet{
private String name;
private int age;
public Dog(String name, int age){
this.name = name;
this.age = age;
}
public void setname(String name){
this.name = name;
}
public void setage(int age){
this.age = age;
}
public String getname(){
return this.name;
}
public int getage(){
return this.age;
}
public String getName(){
return this.name;
}
public int getAge()
{
return this.age;
}
public boolean equals(Object obj){
if(this == obj){
return true;
}
if(obj == null){
return false;
}
if(!(obj instanceof Dog)){//如果obj不是cat的子类,返回false
return false;
}
Dog d = (Dog) obj;
if(this.name.equals(d.name) && this.age == d.age){
return true;
}
return false;
}
public String toString(){
return "狗的名字:" + this.name + "; " + "年龄: " + this.age +";\n";
}
}