Kotlin is an object-oriented (OO) language, and classes are the main element of an OO language. This chapter will delve into the details of working with classes in Kotlin.Â
Even if you have experience with Java or similar languages, you can still learn from this chapter. There are a lot of differences from Java when working with classes, such as the constructor syntax, default visibility modifiers, properties, and so on. Kotlin also has some unique features not found in other languages, such as sealed and data classes.
In this chapter, you will learn about the following:
- Classes
- Properties
- Class constructors
- Nested classes
- Enum classes
- Data classes
- Inheritance
- Overriding members
- Abstract classes
- Interfaces
- Interfaces versus abstract classes
- The object keyword
- Class delegation
- Sealed classes
- Smart casts