...

/

Classes and Objects (part-I)

Classes and Objects (part-I)

Learn about the basics of object orientation in Kotlin.

Overview

Classes in Kotlin offer many improvements over those in Java, resulting in more compact and better code.

Kotlin, like Java, is an object-oriented programming language with a remarkable number of functional programming features.

Kotlin offers classes with encapsulation, inheritance, polymorphism, and all other object-oriented paradigms, also known from Java.

On the other hand, the syntax is a bit different, enabling you to write more compact, easier-to-read, and on the whole, simply better code.

A simple class example

Press + to interact
class Person {
val firstName = "Alex"
val lastName = "Prufrock"
}

As in Java, the declaration of a class starts with the keyword, ...