interface Study {//接口+interface
fun readbooks()
fun dohomework(){
println("do homework default implementation")//在接口中加函数体的内容,代表着dohomework这个函数默认实现,
//就是说在student继承哪里,可以不用override定义接口函数,不会报错,但readbook不行,因为没有加函数体
}
}
class Student (name :String,age :Int):person(name,age),Study{//接口加继承的函数,person是类的继承,Study是接口
override fun readbooks() {//override接口调用关键字,实现接口中的函数
println(name+"is reading")
}
/*override fun dohomework() {
println(name+"is doing homework.")
}*/
}
/*fun main() {
//val a =Student("123654",5,"nie",18)
//val a=Student()
//val a=Student("nie",18)
val a=Student("niw",5)
//a.name="nie"
//a.age=18
println(a.name+" is eating,he is "+a.age+" years old,他是 ")//+a.*gr
interface Study {//接口+interface fun readbooks() fun dohomework(){ println("do homework default implementation")//在接口中加函数体的内容,代表着dohomework这个函数默认实现, //就是说在student继承哪里,可以不用override定义接口函数,不会报错,但readbook不行,因为没有加函数体 }}class St..