Wrapping Up
Kotlin’s support to build a hierarchy of classes goes beyond the support provided in Java. Interfaces are almost the same in both languages, except in the way they are defined—Kotlin has no default keyword, and static methods go into companion objects even for interfaces. Kotlin’s nested and inner classes also differ from the same concepts in Java—unlike Java, Kotlin makes a clear distinction between nested and inner classes, to make the intent clear. Classes are final by default, but not all open classes are widely inheritable—you can control inheritance using sealed classes if you like. Kotlin places restrictions around inheritance so classes don’t accidentally serve as a base class. This forces you to make the intent explicit ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access