1. class
class Item(
val name: String,
val price: Int
)
val item = Item("Book", 10000)
println("item name is ${item.name}, price is ${item.price}")
2. interface
class Item(
val name: String,
val price: Int
) : ItemTrade {
override fun buy() {
println("[buy] $name")
}
override fun sell() {
println("[sell] $name")
}
}
interface ItemTrade {
fun buy()
fun sell()
}
val item = Item("Book", 10000)
println("item name is ${item.name}, price is ${item.price}")
item.buy()
item.sell()
'개발이 좋아서 > Kotlin이 좋아서' 카테고리의 다른 글
[Api 만들기] (0) | 2024.01.02 |
---|---|
[spring setting] (0) | 2024.01.02 |
[function] (0) | 2024.01.02 |
[if / when] (0) | 2024.01.02 |
[변수 알아보기] (1) | 2024.01.02 |