O'Reilly logo

Android Development with Kotlin by Igor Wojda, Marcin Moskala

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inheritance

As we already know, a supertype of all Kotlin types is Any. It is the equivalent of the Java Object type. Each Kotlin class explicitly or implicitly extends the Any class. If we do not specify the parent class, the Any will be used implicitly set as parent for the class:

    class Plant // Implicitly extends Any 
    class Plant : Any // Explicitly extends Any 

Kotlin, like Java, promotes single inheritance, so a class can have only one parent class, but it can implement multiple interfaces.

In contrast to Java, every class and every method in Kotlin is final by default. This plays along with the Effective Java Item 17: Design and document for inheritance or else prohibit it rule. This is used to prevent unexpected behavior from a subclass ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required