Kotlin Class Inheritance Inheriting methods from a class


Example

Defining the base class:

open class Person {
    fun jump() {
        println("Jumping...")
    }
}

Defining the derived class:

class Ninja: Person() {
    fun sneak() {
        println("Sneaking around...")
    }
}

The Ninja has access to all of the methods in Person

fun main(args: Array<String>) {
    val ninja = Ninja()
    ninja.jump()  // prints: 'Jumping...'
    ninja.sneak() // prints: 'Sneaking around...'
}