How can constants be defined in Java?

There are two ways to define constants in Java.

  1. last
  2. last
final int MAX_VALUE = 100;
final double PI = 3.1415926;
final String MESSAGE = "Hello, World!";
  1. list of options or choices
  2. list of options or choices
enum Color {
    RED, GREEN, BLUE;
}

In the example above, Color is an enumeration type that consists of three constant objects: RED, GREEN, and BLUE.

bannerAds