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