201711671132《java实用教程》第六章学习总结
一、教材学习内容总结
(1)教材学习中的问题和解决过程
(2)代码调试内容总结(课后习题),无问题
1、Animal.java
public interface Animal {
public abstract void cry();
public abstract String getAnimalName();
}
Simulator.java
public class Simulator {
public void playSound(Animal animal) {
System.out.print("现在播放"+animal.getAnimalName()+"类的声音:");
animal.cry();
}
}
Dog.java
public class Dog implements Animal {
public void cry() {
System.out.println("汪汪...汪汪");
}
public String getAnimalName() {
return "狗";
}
}
Cat.java
public class Cat implements Animal {
public void cry() {
System.out.println("喵喵...喵喵");
}
public String getAnimalName() {
return "猫";
}
}
Application.java
public class Example5_13 {
public static void main(String args[]) {
Simulator simulator = new Simulator();
simulator.playSound(new Dog());
simulator.playSound(new Cat());
}
}
(3)无疑问