Syntax

Java Define an Enum Syntax

In Java, define an enum: defines a fixed set of constants — enum Color { RED, GREEN, BLUE }

Quick Answer

Syntax
enum Color { RED, GREEN, BLUE }
JavaSyntax

Define an Enum

Code example
enum Color { RED, GREEN, BLUE }

Defines a fixed set of constants.

Learn More

How to define an enum in Java

  1. Open your Java file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Java Define an Enum Syntax

Use enum Color { RED, GREEN, BLUE }.

Related Syntax References

Frequently asked questions

What is the Java syntax for define an enum?

Use this pattern: enum Color { RED, GREEN, BLUE }

Can I copy this Java code example?

Yes. Use Copy code and adapt the example to your program.

Is this Java syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify