面试题答案
一键面试interface MyInterface {
fun defaultMethod(): String {
return "这是默认实现"
}
fun overrideMethod(): String
}
class MyClass : MyInterface {
override fun overrideMethod(): String {
return "这是覆盖后的实现"
}
fun callDefaultMethod() {
println(defaultMethod())
}
}
你可以通过以下方式测试代码:
fun main() {
val myObject = MyClass()
myObject.callDefaultMethod()
println(myObject.overrideMethod())
}