Sobes.tech
Junior — Middle

Mis on alus Kotlinis klasside loomis?

sobes.tech AI

Vastus AI-lt

In Kotlin, the keyword class is the foundation for creating classes. The class defines a template for creating objects, including properties and methods. For example:

class Person(val name: String, var age: Int) {
    fun greet() {
        println("Hello, my name is $name and I am $age years old")
    }
}

val person = Person("Ivan", 30)
person.greet()  // Will output: Hello, my name is Ivan and I am 30 years old

Kotlin also supports inheritance, interfaces, and other object-oriented features.