tags:

views:

520

answers:

5

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.

+3  A: 

In Java, Enum is now a type of class, so you can have an enum object.

Dana the Sane
That's the Java answer. Is the same true for C#?(Too bad you can't set more than one reply as answer)
Mr Grieves
Yeah, I don't know much about C#, but in most cases they seem pretty similar. VBNight has provided a reasonable answer though.
Dana the Sane
I believe C# enums are like ints rather than objects. The same is true in C and C++. I believe C++0x is due to have Java-like enums.
Tom Hawtin - tackline
for java, i would think "object is to class as enum is to class-file". object is an instance of a class, and enum is an instance of the class file from which it was loaded. oO
Johannes Schaub - litb
+5  A: 

"Enum is to Value Type"

Enums are strongly typed constants

In the C# tradition, they are strongly typed, meaning that an enum of one type may not be implicitly assigned to an enum of another type even though the underlying value of their members are the same.

Enums are value types, which means they contain their own value, can't inherit or be inherited from, and assignment copies the value of one enum to another.

Enums are used and referred to with both lower case, enum, and upper case, Enum. The relationship between the two is that the C# type, enum, inherits the Base Class Library (BCL) type, Enum. Use the C# type, enum, to define new enums and use the BCL type, Enum, to implement static enum methods.

Source: http://www.csharp-station.com/Tutorials/Lesson17.aspx

VBNight
+12  A: 

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.

Vojislav Stojkovic
+2  A: 

Object is to class as enum is to set.

Jeff Kotula
A: 

An Object is an instance of a class. enum is an example of a keyword.

Peter Lawrey