繼承類的欄位
定義基類:
open class BaseClass {
val x = 10
}
定義派生類:
class DerivedClass: BaseClass() {
fun foo() {
println("x is equal to " + x)
}
}
使用子類:
fun main(args: Array<String>) {
val derivedClass = DerivedClass()
derivedClass.foo() // prints: 'x is equal to 10'
}