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.