0% found this document useful (0 votes)
12 views2 pages

Java - Enum Class

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Java - Enum Class

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

01/02/2024, 23:53 Java - Enum Class

Java - 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 [Link] 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 −

[Link]

Java Enum Class Example


Following example showcases the usage of enum in if and switch statements.

package [Link];
public class EnumDemo {
public static void main(String args[]) {

[Link] 1/2
01/02/2024, 23:53 Java - Enum Class

//print an Enum
[Link]([Link]);

Mobile mobile = [Link];


//Usage in IF statment
if(mobile == [Link]) {
[Link]("Matched");
}
//Usage in Swith statment
switch(mobile) {
case Samsung:
[Link]("Samsung");
break;
case Nokia:
[Link]("Nokia");
break;
case Motorola:
[Link]("Motorola");
}
}
}
enum Mobile {
Samsung,
Nokia,
Motorola
}

Output

Let us compile and run the above program, this will produce the following result −

Motorola
Matched
Samsung

[Link] 2/2

You might also like