-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCat.java
More file actions
37 lines (29 loc) · 900 Bytes
/
Copy pathCat.java
File metadata and controls
37 lines (29 loc) · 900 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
package studyjava;
/*1. 该类必须包含String属性来存宠物的名字。
2. 定义一个构造器,它使用String参数指定猫的名字;该构造器必须调用超类构造器来指明所有的猫都是四条腿。
3. 另定义一个无参的构造器。该构造器调用前一个构造器(用this关键字)并传递一个空字符串作为参数
4. 实现Pet接口方法。
5. 实现eat方法。
*/
public class Cat extends Animal implements Pet {
String name;
public Cat(String name) {
super(4);
this.name = name;
}
public Cat() {
this(" ");
}
public void eat() {
System.out.println("cat eat");
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public void play() {
System.out.println(name + "is playing");
}
}