kotlin之open class继承
2020-05-22 本文已影响0人
张漂亮1号
7 kotlin之class继承open
open表示可继承,extends也被改为:
open class Car(brand: String) {
var brand: String = brand
fun showBrand() {
println("This brand is $brand ")
}
}
class Lexus : Car("Lexus") {}
class Honda : Car("Honda") {}
fun main() {
var car = Car("Toyota")
var lexus = Lexus()
var honda = Honda()
car.showBrand()
lexus.showBrand()
honda.showBrand()
}
image
喜欢可以加Q群号:874826112,一起学习,成长,交流工作经验,
记得要点赞,评论哦😯;
更多相关内容请点击主页查看,有你想不到的惊喜😂....
简书: https://www.jianshu.com/u/88db5f15770d