100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Kotlin

Enum Classes in Kotlin

Enum classes define a fixed set of singleton constants that can carry properties and methods.

Advanced OOPBeginner7 min readJul 8, 2026
Analogies

Introduction

An enum class in Kotlin represents a fixed collection of constants, where each constant is a singleton instance of the enum type. Enums are useful whenever a value can only take one of a limited number of known options, such as directions, days of the week, or order statuses. Unlike plain constants, enum constants can carry properties and methods, making them more powerful than in many other languages. Each constant listed in an enum class is a singleton object of that enum type. Enum classes can define a constructor and properties, letting each constant carry its own data. They can also declare abstract methods and provide a different implementation for each constant using a body block. Kotlin provides built-in support via values() (or entries in newer versions) to list all constants, valueOf(name) to look one up by name, plus .ordinal for its position and .name for its identifier.

🏏

Cricket analogy: Just as a match result can only be WIN, LOSS, or TIE (a fixed enum of outcomes), each match-day squad slot like WICKETKEEPER is a singleton role carrying its own stats such as MS Dhoni's keeping average, not just a bare label.

Syntax

kotlin
enum class Direction {
    NORTH, SOUTH, EAST, WEST
}

Example

kotlin
enum class Op {
    PLUS {
        override fun apply(a: Int, b: Int) = a + b
    },
    MINUS {
        override fun apply(a: Int, b: Int) = a - b
    };

    abstract fun apply(a: Int, b: Int): Int
}

fun main() {
    println(Op.PLUS.apply(3, 4))
    println(Op.MINUS.apply(10, 6))
    println(Op.PLUS.name)
    println(Op.PLUS.ordinal)
}

Output

kotlin
7
4
PLUS
0

Key Takeaways

  • Each enum constant is a singleton instance of the enum class.
  • Enum classes can have constructors, properties, and methods.
  • Individual constants can override abstract methods with their own implementation.
  • values()/entries and valueOf() let you enumerate and look up constants.
  • .ordinal gives position and .name gives the constant's identifier.

Practice what you learned

Was this page helpful?

Topics covered

#Kotlin#KotlinProgrammingStudyNotes#Programming#EnumClassesInKotlin#Enum#Classes#Syntax#Example#OOP#StudyNotes#SkillVeris