As we discussed in Chapter 3, Understanding Programming Paradigms in Kotlin, Kotlin fully supports Object-Oriented Programming (OOP). This probably comes as no surprise, given the popularity of OOP in modern languages and Kotlin's ties to the JVM and other JVM-based languages such as Java.
OOP in Kotlin shares many similarities with Java, but there are important differences as well, as in the following examples:
- Numeric types in Kotlin are all classes, even if they are represented internally as primitive values.
- Classes are closed by default.
- Interfaces may contain properties.
Kotlin also aims to adopt learning and best practices from years of Java to make modeling data easier. Toward this goal, Kotlin provides additional modifiers for creating certain families of classes:
- Sealed classes provide compiler support for defining restricted...