Thuta Learning
IntermediateProgrammingbeginner

Inheritance

Relax. We'll talk through this in plain words — no textbook voice.

Inheritance is the OOP concept where one class can inherit and use another class's properties and functions. In Kotlin, classes aren't inheritable by default — you have to mark whatever class or function you want to allow inheriting from as open.

kotlin
open class Animal {
    open fun makeSound() {
        println("Animal sound")
    }
}

class Dog : Animal() {
    override fun makeSound() {
        println("Woof!")
    }
}

fun main() {
    val dog = Dog()
    dog.makeSound()
}
You should see
Woof!

Summary

Inheritance lets you keep common behavior in a parent class while child classes override it as needed.

Easy traps

  • If you don't mark the parent class or function as open, a child class can't inherit or override it.
Inheritance | Thuta Learning