Course
Enum Class
Java Tutorial
This Java tutorial is tailored for newcomers, offering a journey from basic principles to complex Java programming techniques. Completing this tutorial equips you with a solid understanding of Java, preparing you for advanced learning. You'll emerge ready to tackle the challenges of becoming a top-tier software engineer, with the skills to innovate and excel in the vast world of software development.
Enum Class
Java Enum Class
Java Enum class is the common base class for all enumeration types. It is a special class that contains a group of pre-defined constant values that are known at the compile-time itself.
Java Enum Class Declaration
Following is the declaration for java.lang.Enum class
public abstract class Enum<E extends Enum<E>> extends Object implements Comparable<E>, Serializable
Java Enum Class Constructors
Java Enum Class Methods
Methods Inherited
This class inherits methods from the following classes
- java.lang.Object
Java Enum Class Example
package com.tutorialspoint;public class EnumDemo { public static void main(String args[]) { //print an Enum System.out.println(Mobile.Motorola);
Mobile mobile = Mobile.Samsung; //Usage in IF statment if(mobile == Mobile.Samsung) { System.out.println("Matched"); } //Usage in Swith statment switch(mobile) { case Samsung: System.out.println("Samsung"); break; case Nokia: System.out.println("Nokia"); break; case Motorola: System.out.println("Motorola"); } }}enum Mobile { Samsung, Nokia, Motorola}
Output
Let us compile and run the above program, this will produce the following result
MotorolaMatchedSamsung
Print Page