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?
✗ Incorrect
The correct keyword to declare an enum class in Kotlin is
enum class.What does the
values() function return when called on an enum class?✗ Incorrect
The
values() function returns an array containing all constants of the enum class.Can enum constants in Kotlin have their own properties?
✗ Incorrect
Enum constants can have properties by defining a constructor in the enum class and passing values to each constant.
What is the superclass of all enum classes in Kotlin?
✗ Incorrect
All enum classes inherit from the built-in
Enum class in Kotlin.Which of the following is a valid enum class declaration?
✗ Incorrect
The correct syntax uses
enum class followed by the name and constants in braces.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.