zoukankan      html  css  js  c++  java
  • 每日代码系列(19)

     1 interface Animal {
     2   public abstract void cry();
     3   public abstract String getAnimalName();
     4 }
     5 class Simulator {
     6   public void playSound(Animal an) {
     7     an.cry();
     8     an.getAnimalName();
     9   }
    10 }
    11 class Dog implements Animal {
    12   public void cry() {
    13     System.out.println("汪汪...");
    14   }
    15   public String getAnimalName() {
    16     return "Dog";
    17   }
    18 }
    19 class Cat implements Animal {
    20   public void cry() {
    21     System.out.println("喵喵...");
    22   }
    23   public String getAnimalName() {
    24     return "Cat";
    25   }
    26 }
    27 public class Test6_4 {
    28   public static void main(String[] args) {
    29     Simulator sim=new Simulator();
    30     sim.playSound(new Dog());
    31     sim.playSound(new Cat());
    32   }
    33 }

    上午Java考试,这是最后一道大题。这能难倒我?

  • 相关阅读:
    gulp备忘
    好文收藏
    妙味H5交互篇备忘
    [CSS3备忘] transform animation 等
    css选择器总结
    flexbox备忘
    函数
    继承2
    在 Swift 中实现单例方法
    浅谈 Swift 中的 Optionals
  • 原文地址:https://www.cnblogs.com/ljydbk/p/14132791.html
Copyright © 2011-2022 走看看