Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

object is to class as enum is to ...?

Tags:

java

c#

enums

object is to class as enum is to ...?



I'm using C# but I'd like the answer for Java as well, if there is one.

Thank you, as always.

like image 364
srmark Avatar asked Feb 06 '09 17:02

srmark


People also ask

What is an enum object?

An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week.

What is a enum object in Java?

An enum is a special "class" that represents a group of constants (unchangeable variables, like final variables). To create an enum , use the enum keyword (instead of class or interface), and separate the constants with a comma.

Is enum class a class?

enum class is not a class definition - the combination of keywords is used to define a scoped enumeration, which is a completely separate entity from a class .

What is enum for?

Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.


1 Answers

It doesn't matter whether we're discussing C# or Java, the sentence cannot be completed the way you expect it to, because of the following fundamental flaw in it: both enum and class are types, whereas an object is a particular instance of a type.

In C#, an enum is a value type that restricts an underlying numeric type by defining acceptable values and (optionally) combinations of those values for the underlying type. Given the following example:

enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };

we say that Days is an enum, while Monday is one of its values.

In Java, an enum is a class defined using special syntax that defines unique, distinguished, publicly accessible instances of it. An enum is final, i.e. it cannot be extended.

like image 166
Vojislav Stojkovic Avatar answered Oct 03 '22 08:10

Vojislav Stojkovic