Enum with Customized Value in Java Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Prerequisite : enum in Java By default enums have their own string values, we can also assign some custom values to enums. Consider below example for that. Examples: enum Fruits { APPLE(“RED”), BANANA(“YELLOW”), GRAPES(“GREEN”); } In above example we can see that the Fruits enum have three members i.e APPLE, BANANA and GRAPES with have their own different custom values RED, YELLOW and GREEN respectively. Now to use this enum in code, there are some points we have to follow:- We have to create parameterized constructor for this enum class. Why? Because as we know that enum class’s object can’t be create explicitly so for initializing we use parameterized constructor. And the constructor cannot be the public or protected it must have private or default modifiers. Why? if we create public or protected, it will allow initializing more than one objects. This is totally against enum concept. We have to create one getter method to get the value of enums. Java // Java program to demonstrate how values can // be assigned to enums. enum TrafficSignal { // This will call enum constructor with one // String argument RED("STOP"), GREEN("GO"), ORANGE("SLOW DOWN"); // declaring private variable for getting values private String action; // getter method public String getAction() { return this.action; } // enum constructor - cannot be public or protected private TrafficSignal(String action) { this.action = action; } } // Driver code public class EnumConstructorExample { public static void main(String args[]) { // let's print name of each enum and there action // - Enum values() examples TrafficSignal[] signals = TrafficSignal.values(); for (TrafficSignal signal : signals) { // use getter method to get the value System.out.println("name : " + signal.name() + " action: " + signal.getAction() ); } } } Output: name : RED action: STOP name : GREEN action: GO name : ORANGE action: SLOW DOWN Comment More info K kartik Improve Article Tags : Java Explore Java BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOP & InterfacesClasses and Objects in Java10 min readAccess Modifiers in Java6 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking15+ min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like