interface Animal { String talk(); } class Frog implements Animal { public String talk() { return "ggg!"; } } class Cat implements Animal { public String talk() { return "miao"; } } class Creature { private Animal state = new Frog(); public void greet() { System.out.println(state.talk()); } public void toCat() { state = new Cat(); } } public class MainClass { public static void main(String args[]) { Creature creature = new Creature(); creature.greet(); creature.toCat(); creature.greet(); } }