package com.tct.freeze.kotlinstudydemo
// interface 接口
interface People {
// 默認方法
fun onFavourite(){
println("Study")
}
// 不實現默認方法
fun onPrint()
}
類實現接口
package com.tct.freeze.kotlinstudydemo
// 類實現接口
class Student : People {
override fun onPrint() {
println("I am a Student")
}
override fun onFavourite() {
super.onFavourite()
}
}
調用
package com.tct.freeze.kotlinstudydemo
fun main(args : Array<String>) {
var mStudent = Student()
mStudent.onPrint()
mStudent.onFavourite()
}
運行結果
I am a Student
Study
Process finished with exit code 0