继承类的字段
定义基类:
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'
}