How to avoid large if-statements and instanceof

前端 未结 9 2371
盖世英雄少女心
盖世英雄少女心 2020-11-29 05:11

Animal

public abstract class Animal {
 String name;

 public Animal(String name) {
  this.name = name;
 }

}

Lion<

9条回答
  •  一向
    一向 (楼主)
    2020-11-29 05:52

    Yes provide a method called action() in abstract class , implement it in both of the child class, one will roar other will runaway

提交回复
热议问题