If the static enumerated type should be extensible the constructor can be declared as
Answers
Answer:
Since enums are effectively classes, you can do pretty much everything with them that you can do with a class. In particular, you can provide one or more constructors for an enum type! That may seem a little weird to you (it does to me), because you never call an enum constructor anywhere in your code, or use the "new" operator to instantiate an enum. The definition of an enum brings the class enum constants into existence. You always work with static fields of an enum, not instances.
You might want to write a constructor when you have enumerations with a close relationship to numeric values.
Answer: The answer is enum type.
If the static enumerated type should be extensible the constructor can be declared as enum type.
Constructors: In object-oriented programming, a function Object() { [native code] } is a particular method of a class or structure that is responsible for setting the default values for a newly formed object of that kind. Constructors are automatically called whenever new objects are formed. This happens automatically.
Explanation:
- Enumeration: A set of named values that represent integral constants are what are referred to as enumeration constants.
- An enumeration is a data type that consists of this set of named values.
- To create a name for each of the values in an enumeration, you must first list (enumerate) all of the values in the enumeration. This is why an enumeration is also known as an enumerated type.
- Because enums are functionally equivalent to classes, we can do virtually anything with them that you could do with a class. Enums are a type of class.
- To be more specific, you are free to supply an enum type with one, two, or even more constructors!
- Because you never invoke an enum function Object() { [native code] } anywhere in your code or use the "new" operator to instantiate an enum, it might strike you as odd.
- It does me, too, because I'm sure it's something you've never done before.
- The class constants for an enum are brought into existence when the definition of an enum is read.
- You never work with instances of an enum; rather, you always work with its static fields.
- When you have enumerations that have a close relationship to numeric values, you may want to consider writing a function Object() { [native code] } for your program.
#SPJ3