Skip to content
Justice Tech School

Inheritance

Classes are final by default. Mark them open to extend and override functions with override.

Example
open class Animal { open fun sound() = "..." }
class Cat : Animal() { override fun sound() = "meow" }
val a: Animal = Cat()
println(a.sound())

Exercise

Allow extending.

 class Animal

Quiz Test

Are classes open by default?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.