October 2019
Intermediate to advanced
434 pages
11h 54m
English
Primary constructors are defined inline with the class declaration using the following syntax:
class Student public constructor(_firstName: String, val lastName: String) { ...}
If the constructor does not require any visibility modifiers or annotations, the constructor keyword can be omitted to reduce the boilerplate:
class Student (_firstName: String, val lastName: String) { }
Within a primary constructor, we can pass arguments and define properties. If the constructor does not require any arguments or properties, then the parentheses can be omitted. In this case, a default empty constructor will be generated by the compiler, allowing the class to be instantiated as if it did have a defined constructor.
The following ...
Read now
Unlock full access