옵션 |
|
Animal.java
public class Animal { String name; public void setName(String name) { this.name = name; } public String getName() { return this.name; } }
Predator.java
public interface Predator { public String getName(); }
Tiger.java
public class Tiger extends Animal implements Predator { }
Lion.java
public class Lion extends Animal implements Predator { }
ZooKeeper.java
public class ZooKeeper { public void feed(Predator predator) { System.out.println("feed "+predator.getName()); } public static void main(String[] args) { Tiger tiger = new Tiger(); tiger.setName("tiger"); Lion lion = new Lion(); lion.setName("lion"); ZooKeeper zooKeeper = new ZooKeeper(); zooKeeper.feed(tiger); zooKeeper.feed(lion); } }
---------------------------
소스코드입니다.