This post originated from an RSS feed registered with Java Buzz
by Javin Paul.
Original Post: Java Enum Example with Constructor
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Java Enum can have Constructor to pass data while creating Enum
constants. One example of passing arguments to enum Constructor is our TrafficLight Enum where
we pass action to each Enum instance e.g. GREEN is associate with go, RED is
associate with stop and ORANGE is
associated with slow down. You can also provide one or more constructor
to your Enum as it also support constructor
overloading. Just note that modifier public
and protected are not allowed to Enum constructor, it will result in
compile time error. By the way We have covered see some enum examples in our
previous posts e.g. Java
Enum Switch Example, Java
Enum valueOf Example and Enum
to String Exmaple in Java, which is good to learn enum in Java.