不对啊!编译的时候有很多问题!
汗,太打击人了,就你会嘛.....
追答这些是基础,要理解,别人可以帮你解决,关键是你自己能不能理解。
public class DoMethod {
public static void main(String[] args) {
System.out.println(new Animal().showAnimal("蓝色", "5"));
}
}
class Animal{
//定义私有参数color
private String color;
//color的get方法
public String getColor() {
return color;
}
//color的set方法
public void setColor(String color) {
this.color = color;
}
//定义私有参数age
private String age;
//age的get方法
public String getAge() {
return age;
}
//age的set方法
public void setAge(String age) {
this.age = age;
}
/**
* 给动物添加color和age的方法,然后输出到Console
* @return 需要打印的字符串
* */
public String showAnimal(String color,String age){
//给动物添加age
this.setAge(age);
//给动物上色
this.setColor(color);
//输出动物的颜色和年龄
return "这是一个" + this.getColor() + "的动物,它已经" + this.getAge() +"岁了。";
}
}