Kotlin ClassesLesson 24Free preview
Kotlin Inheritance
This lesson is part of Kotlin · All levels
Summary
This lesson discusses inheritance in Kotlin to build a hierarchy of parent classes (superclass) and subclasses (subclass). By default, all classes in Kotlin are 'final' (closed). To allow a class to be inherited or a method to be overridden, the programmer must explicitly mark it with the keyword 'open'.
Key points
- The inheritance is declared using the colon symbol ':' after the name of the subclass
- The parent class must be given an 'open' modifier to be inherited
- The method that wants to replace its behavior in the subclass must be given an 'open' modifier in the parent and an 'override' in the child.
- The keyword 'super' is used to call a constructor or method belonging to the parent class
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.