Enum Type Implementing the Command Interface - Java Language Basics

Java examples for Language Basics:enum

Description

Enum Type Implementing the Command Interface

Demo Code

enum CommandList implements Command {
  RUN {/* w  w  w  .j av  a2s .com*/
    public void execute() {
      System.out.println("Running...");
    }
  },
  JUMP {
    public void execute() {
      System.out.println("Jumping...");
    }
  };

  public abstract void execute();
}

interface Command {
  void execute();
}

public class Main {
  public static void main(String... args) {
    for (Command cmd : CommandList.values()) {
      cmd.execute();
    }
  }
}

Result


Related Tutorials