4 Classes, objects, and interfaces
This chapter covers
- Classes and interfaces
- Nontrivial properties and constructors
- Data classes
- Class delegation
- Using the
object
keyword
In this chapter, you’ll gain a deeper understanding of working with classes and interfaces in Kotlin. You already saw the basic syntax for declaring a class in section 2.2, and you know how to declare methods and properties, use simple primary constructors (aren’t they nice?), and work with enums. But there’s a lot more to see and learn on the topic! Kotlin’s classes and interfaces differ a bit from what you might be used to from Java: for example, interfaces can contain property declarations. Kotlin’s declarations are final
and public
, by default. In addition, nested classes ...
Get Kotlin in Action, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.