使用Java语言书写草莓熊代码
时间: 2023-08-04 18:03:51 浏览: 334
很好,以下是一个简单的草莓熊类的Java代码:
```
public class StrawberryBear {
private String name;
private int age;
private String color;
public StrawberryBear(String name, int age, String color) {
this.name = name;
this.age = age;
this.color = color;
}
public void eat() {
System.out.println(name + " is eating strawberries!");
}
public void sleep() {
System.out.println(name + " is sleeping!");
}
public void play() {
System.out.println(name + " is playing with friends!");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
```
以上代码定义了一个草莓熊类,包含了草莓熊的名称、年龄、颜色以及草莓熊的行为,例如吃草莓、睡觉和玩耍等。可以根据需要添加其他属性或方法。
阅读全文