Sobes.tech
Junior — Middle

Are classes in Kotlin inheritable by default without additional modifiers?

sobes.tech AI

Answer from AI

In Kotlin, classes are not inheritable by default. To make a class inheritable, it must be declared with the open modifier.

Example:

open class Base {
    fun hello() = println("Hello")
}

class Derived : Base() {
}

If you remove open from Base, attempting to inherit from it will result in a compile-time error. This is done to enhance safety and prevent unwanted inheritance.

Are classes in Kotlin inheritable by default without… - sobes.tech