201711671132《java实用教程》第五章学习总结

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Yyingyunxi/article/details/84948508

201711671132《java实用教程》第五章学习总结

一、教材学习内容总结

(1)教材学习中的问题和解决过程

(2)代码调试内容总结(课后习题),无问题

1、Animal.java

public abstract class 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 extends Animal {

public void cry() {

System.out.println("汪汪...汪汪");

}

public String getAnimalName() {

return "狗";

}

}

Cat.java

public class Cat extends 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)无疑问

 

展开阅读全文

没有更多推荐了,返回首页