// enums/cartoons/EnumImplementation.java // ©2015 MindView LLC: see Copyright.txt // An enum can implement an interface package enums.cartoons; import java.util.*; import com.mindviewinc.util.*; enum CartoonCharacter implements Generator { SLAPPY, SPANKY, PUNCHY, SILLY, BOUNCY, NUTTY, BOB; private Random rand = new Random(47); @Override public CartoonCharacter next() { return values()[rand.nextInt(values().length)]; } } public class EnumImplementation { public static void printNext(Generator rg) { System.out.print(rg.next() + ", "); } public static void main(String[] args) { // Choose any instance: CartoonCharacter cc = CartoonCharacter.BOB; for(int i = 0; i < 10; i++) printNext(cc); } } /* Output: BOB, PUNCHY, BOB, SPANKY, NUTTY, PUNCHY, SLAPPY, NUTTY, NUTTY, SLAPPY, */