定义一个类叫猫,毛色能做什么事,自我介绍,输出一只叫黑猫一只叫白猫都喜欢吃鱼
毛色能做什么事
这句话是什么意思?
这样?
public class Cat {
private String color;
public Cat(String color) {
super();
this.color = color;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String doWhat() {
return "爱吃鱼";
}
public void IntroduceSelf() {
System.out.println(this.color + "猫" + this.doWhat());
}
public static void main(String[] args) {
Cat aCat = new Cat("黑");
Cat bCat = new Cat("白");
aCat.IntroduceSelf();
bCat.IntroduceSelf();
}
}