0
0
Kotlinprogramming~5 mins

Enum class declaration in Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an enum class in Kotlin?
An enum class in Kotlin is a special class that represents a group of constants. It helps to define a fixed set of related values, like days of the week or directions.
Click to reveal answer
beginner
How do you declare a simple enum class in Kotlin?
Use the keyword <code>enum class</code> followed by the name and list of constants inside curly braces. For example:<br><pre>enum class Direction { NORTH, SOUTH, EAST, WEST }</pre>
Click to reveal answer
intermediate
Can enum constants have properties and methods in Kotlin?
Yes! Enum constants can have their own properties and methods. You can define a constructor for the enum class and add functions to customize behavior.
Click to reveal answer
intermediate
What is the default superclass of an enum class in Kotlin?
All enum classes in Kotlin inherit from the built-in <code>Enum</code> class automatically. This gives them useful functions like <code>values()</code> and <code>valueOf()</code>.
Click to reveal answer
beginner
How do you access all constants of an enum class?
You can call the <code>values()</code> function on the enum class to get an array of all constants. For example:<br><pre>Direction.values()</pre>
Click to reveal answer
Which keyword is used to declare an enum class in Kotlin?
Aenum class
Benum
Cclass enum
DenumType
What does the values() function return when called on an enum class?
AThe first enum constant
BA list of all enum constants
CThe number of enum constants
DA random enum constant
Can enum constants in Kotlin have their own properties?
AOnly if they extend another class
BNo, enum constants are fixed and cannot have properties
CYes, by defining a constructor in the enum class
DOnly if declared as data classes
What is the superclass of all enum classes in Kotlin?
ANothing
BAny
CObject
DEnum
Which of the following is a valid enum class declaration?
Aenum class Color { RED, GREEN, BLUE }
Benum Color { RED, GREEN, BLUE }
Cclass enum Color { RED, GREEN, BLUE }
Denumclass Color { RED, GREEN, BLUE }
Explain how to declare an enum class in Kotlin and give an example.
Think about how you list fixed options like directions or colors.
You got /4 concepts.
    Describe how enum constants can have properties and methods in Kotlin.
    Consider how each constant can carry extra information.
    You got /4 concepts.