根据如下需求,完成代码(按照标准格式写),然后在测试类中测试
动物类Animal
属性:姓名name,年龄age
行为:吃饭eat
class Animal {
public static void main(String[] args) {
Animall a =new Animall();
a.setName("猫");
a.setAge(3);
System.out.println(a.getName()+" "+a.getAge());
a.eat();
}
}
class Animall{
private String name;
private int age;
public void setName(String name){
this.name =name;
}
public String getName(){
return name;
}
public void setAge(int age)
{
this.age =age;
}
public int getAge()
{
return age;
}
public void eat(){
System.out.println("吃饭");
}
}
|
|