dark32
dark32

Reputation: 279

How are enumerations different from classes?

I am new to Java and to me enumerations and classes look a lot similar to me except the fact that enumerations have pre built constants. So, I wanted to ask two things. How are enumerations and classes different and why should we use enumerations instead of class?

Upvotes: 0

Views: 42

Answers (1)

duffymo
duffymo

Reputation: 308763

Enumerations are classes. They extend the Enum parent.

I think of enumerations as typesafe, restricted, self-describing lists of constants that my application will use. You don't use them instead of classes; they're complimentary.

You choose to use an enumeration if you have a finite list of related constants.

Upvotes: 1

Related Questions