5.12 应用举例(略)
1.设计一个动物声音”模拟器“,模拟许多动物叫声
编写抽象类Animal,2个抽象方法cry ()和getAnimalName()
public abstract class Example_12_Animal {
void cry() {
};
void getAnimalNAme() {
};
}
public class Example12_Dog {
String dogCry = "汪····";
String dogName = "狗";
void getAnimalNAme() {
System.out.println(dogName);
};
void cry() {
System.out.println(dogCry);
};
}
public class Exmaple12_Cat {
String catCry = "喵····";
String catName = "猫";
void getAnimalNAme() {
System.out.println(catName);
};
void cry() {
System.out.println(catCry);
};
}
public class Example_12 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Example12_Dog dog=new Example12_Dog();
Exmaple12_Cat cat=new Exmaple12_Cat();
dog.getAnimalNAme();
dog.cry();
cat.getAnimalNAme();
cat.cry();
}
}
//输出结果
//狗
//汪····
//猫
//喵····