Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between uppercase Enum and lowercase enum

Tags:

java

enums

What is the difference between using the lowercase keyword enum and the uppercase class name Enum to define a class?

public enum Apple {
    RedDelicious, GrannySmith;
}

public Enum Pony {
    Earth, Pegasus, Unicorn
}

The second version is not correct anyway, as I am not familiar with the correct syntax of that method of creating Enums, but apparently, something similar is possible.

My apologies if this question seems as though it lacks research effort, but that is not the case; due to the casing issue, this information is not easy to find via Google, IMHO.

like image 550
Southpaw Hare Avatar asked Dec 21 '22 07:12

Southpaw Hare


2 Answers

The enum keyword is part of the Java language. Enum is the name of the Class object that represents an enum; that is, it is the common base class for all enum values. It defines the methods that all enum objects inherit: name(), ordinal(), etc. Think of it like an analogy question from the old SAT: enum is to Enum as class is to Object.

Always use enum in your code for declaring enumerations.

like image 105
Ted Hopp Avatar answered Feb 02 '23 00:02

Ted Hopp


enum is the reserved word used to define a new enumeration.

Enum is an abstract class, that comes with the JDK.

If you want to define a new enumeration, use enum

You can refer to Enum documentation here if you want any further clarification.

like image 30
Rodrigo Sasaki Avatar answered Feb 02 '23 00:02

Rodrigo Sasaki