/*
动物类Animal
属性:姓名name,年龄age
行为:吃饭eat,睡觉sleep
*/
class Animal_Test010 {
public static void main(String[] args) {
Animal a1 = new Animal();
a1.setName("老虎");
a1.setAge(12);
System.out.println(a1.getName()+"..."+a1.getAge());
a1.eat();
a1.sleep();
}
}
class Animal {
private String name;
private int age;
public Animal() {}
public Animal(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("睡觉");
}
}
|
|