Inheritance
Inheritance is one of the main aspects of object-oriented programming. Basically, it allows classes (subclasses) to inherit members from base types (superclasses). They usually have their own functions and properties, which are not found in the base type. With inheritance, you can achieve code reuse, build class hierarchies, or extend base types with additional functionality.
Let's take a look at an example. We have the old User class we used in this chapter, and let's say we also need to have a class that represents administrator users, which will have the same properties as the base User class plus one additional property, role. We can say this would be a good use of inheritance, so let's create the AdminUser class, which extends the base User class:
open class User(var firstName: String, var lastName: String, var birthYear: String) class AdminUser(firstName: String, lastName: String, birthYear: String, var role: String): User(firstName, lastName...