Classes and Inheritance
Classes and Inheritance
Classes
Classes in Kotlin are declared using the keyword class:
class Invoice { }
The class declaration consists of the class name, the class header (specifying its type parameters, the primary constructor etc.) and the class body, surrounded by curly braces. Both the header and the body are optional; if the class has no body, curly braces can be omitted.
class Empty
Constructors
A class in Kotlin can have a primary constructor and one or more secondary constructors. The primary constructor is part of the class header: it goes after the class name (and optional type parameters).
class Person constructor(firstName: String) { }
If the primary constructor does not have any annotations or visibil