Foggy day

Kotlin - class extension 본문

Kotlin

Kotlin - class extension

jinhan38 2021. 3. 15. 21:24

Add open in front of class to extend class in kotlin.

class KotlinPlayGroundActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_kotlin_play_ground)

        val people = People("jinhan", 30)
        println("name : ${people.name}, age : ${people.age}")

    }

    class People(name: String, age: Int) : Person(name, age) {
    }

    open class Person(val name: String, val age: Int) {

    }
}

'Kotlin' 카테고리의 다른 글

Kotlin - companion object  (0) 2021.03.16
Kotlin - destructing  (0) 2021.03.16
Kotlin - data class  (0) 2021.03.15
Kotlin - constructor  (0) 2021.03.15
Kotlin - variable initialization  (0) 2021.03.15