BeginnerOOP
Class Example
Define a class with properties.
kotlin
class Car {
var brand = "Toyota"
var year = 2024
}
fun main() {
val car = Car()
println(car.brand)
println(car.year)
}Output
Toyota
2024
Explanation
Car is a class with two properties. Instantiate it with Car() and access properties with dot notation.