Java.lang.Enum Class

Java Enum Class


The Enum class in the Java.lang package is the universal basis class for all Java language enumeration types. So let us Start with Java.lang.Enum Class.



Class declaration

The declaration of java.lang.Enum class is:


public abstract class Enum<E extends Enum<E>>
  extends Object
    implements Comparable<E>, Serializable

Class Constructor

S.N Constructors & Description
1. protected Enum(String name, int ordinal)
Sole constructor.

java.lang.Enum Methods

The java.lang.Enum class has a number of methods which are listed below:


Member Methods


S.N Methods & Description
1. protected Object clone()
Throws CloneNotSupportedException.
2. int compareTo(E o)
Compares this enum with the specified object for order.
3. boolean equals(Object other)
Returns true if the specified object is equal to this enum constant.
4. protected void finalize()
enum classes cannot have finalize methods.
5. Class<E> getDeclaringClass()
Returns the Class object corresponding to this enum constant’s enum type.
6. int hashCode()
Returns a hash code for this enum constant.
7. String name()
Returns the name of this enum constant, exactly as declared in its enum declaration.
8. int ordinal()
Returns the ordinal of this enumeration constant (its position in its enum declaration, where the initial constant is assigned an ordinal of zero).
9. String toString()
Returns the name of this enum constant, as contained in the declaration.
10. static <T extends Enum<T>> T valueOf(Class<T> enumType, String name)
Returns the enum constant of the specified enum type with the specified name.


Methods inherited

This class inherits the methods of following class:


  • java.lang.Object


To open the online compiler click here.


Also Read: Java – Switch

Leave a Reply

Your email address will not be published. Required fields are marked *