动物类Animal
属性:姓名name,年龄age
行为:吃饭eat,睡觉sleep
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();
a.sleep();
}
}
class Animall{
private String name;
private int age;
public Animall(){}
public Animall(String name, int age){
this.name = name;
this.age = 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("吃饭");
}
public void sleep(){
System.out.println("睡觉");
}
}
|
|