Sobes.tech
Junior — Middle

What is the basis for creating classes in Kotlin?

sobes.tech AI

Answer from AI

In Kotlin, the keyword class is used as the basis for creating classes. A 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.

What is the basis for creating classes in Kotlin… - sobes.tech