Enums Flashcards
1
Q
What are general enum methods?
A
valueOf, name, ordinal, values
2
Q
How to check equality of enums?
A
==
2
Q
Are enums extendable?
A
No
3
Q
Can enums implement interfaces?
A
Yes
3
Q
When do enums initialize?
A
When first time their values are called or evaluated. If there is static reference to it, then it is called then. Their constructor is called as many times as there are values.
4
Q
How do we use enums in switch statements?
A
We use their reference, not actual name of the enum
4
Q
How do simple enums look like?
A
They only contain values of enum.
5
Q
How do complex enums look like?
A
- They contain private constructor, or constructor where access modifier is omitted
- Each enum value contains constructor call with defined literal. Also, each enum value can contain normal methods
- Between each value there is comma. If enum contains constructor or methods, values end with “;”.
- If values have methods, then those values must implement interface
- If values don’t have methods, then enum implements interface
- There cannot be combination of values with methods, and without