Files
excel-download/kotlin-basic/src/main/kotlin/9_Class.kt
2023-02-24 01:24:45 +09:00

28 lines
603 B
Kotlin

class Coffee (
var name: String = "", // 기본값 지정
var price: Int = 0,
) {
val brand: String
get() {
return "스타벅스"
}
var quantity: Int = 0
set(value) {
if (value > 0) {
field = value // 필드에 접근하여 데이터 저장
}
}
}
class EmptyClass
fun main() {
val coffee = Coffee();
coffee.name = "아이스 아메리카노"
coffee.price = 2000
coffee.quantity = 1
println("${coffee.brand}: ${coffee.name} ${coffee.quantity}개 가격은 ${coffee.price}")
}