iT邦幫忙

2021 iThome 鐵人賽

DAY 26
0
Mobile Development

刮掉Web Development的我,與撿到的Android Development系列 第 26

[Lesson26] Kotlin - Inheritance

如果類別要被繼承,可以使用 open 修飾

open class Person(var name : String, var age : Int) {
}
class Student(name : String, age : Int, var no : String) : Person(name, age) {
}

fun main(args: Array<String>) {
    val s =  Student("Runoob", 18, "No.1")
    println("姓名: ${s.name}")
    println("年齡: ${s.age}")
    println("座號: ${s.no}")
}

謝謝大家願意花時間閱讀,小弟弟我在此鞠躬/images/emoticon/emoticon41.gif


上一篇
[Lesson25] Kotlin - Array
下一篇
[Lesson27] Kotlin - Interface
系列文
刮掉Web Development的我,與撿到的Android Development30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言