Browse topics
Object Oriented Kotlin
Kotlin Classes
Declare classes, properties, constructors and init blocks.
kotlin classesClass Declaration in KotlinA class is a blueprint for creating objects. A Kotlin example with source code and sample output.kotlin classesClass Properties in KotlinProperties store state inside a class. A Kotlin example with source code and sample output.kotlin classesClass Constructors in KotlinConstructors initialize object properties when an object is created. A Kotlin example with source code and sample output.kotlin classesPrimary Constructor in KotlinPrimary constructor is part of the class header. A Kotlin example with source code and sample output.kotlin classesSecondary Constructor in KotlinSecondary constructors are declared inside the class body using constructor keyword. A Kotlin example with source code and sample output.kotlin classesinit Block in Kotlininit block contains initialization code for a class. A Kotlin example with source code and sample output.kotlin classesNested and Inner Classes in KotlinA nested class is declared inside another class and does not hold a reference to the outer instance. A Kotlin example with source code and sample output.kotlin classesCustom Getters and Setters in KotlinProperties can define custom get and set logic while keeping field-like syntax. A Kotlin example with source code and sample output.
Related topics
Inheritance Open classes, overriding, abstract classes and inheritance rules. Interfaces Define and implement interfaces, functional interfaces and properties. Data Classes Data class declaration, copy, destructuring and equals/hashCode. Objects & Enums Object declarations, companion objects, expressions and enum classes. Sealed Classes Sealed classes, when expressions and restricted type hierarchies.