kotlin抽象类
abstract class Student(name: String, age: Int) {
init {
println("name:$name")
println("age:$age")
}
//非抽象函数
fun demo() {
println("非抽象函数")
}
//抽象函数
abstract fun func(message: String)
}
class School(name: String, age: Int) : Student(name, age) {
override fun func(message: String) {
println(message)
}
}
fun main(args: Array<String>) {
val obj = School("zhang", 18)
obj.func("android")
obj.demo()
}
输出:
name:zhang
age:18
android
非抽象函数