interface Movable {
var maxSpeed: Int
var wheels: Int
fun move(movable: Movable): String
}

class Car(_name: String, override var wheels: Int = 4) : Movable {
override var maxSpeed: Int
get() = 1
set(value) {}

override fun move(movable: Movable): String {
}

}

Kotlin 接口 interface 默认实现了open。并且可以提供默认实现_Java

Kotlin规定。所有的接口属性和函数都要使用override关键字。接口中定义的函数并不需要open关键字修饰。他们默认就是open的

默认实现

interface Movable {
val maxSpeed: Int
get() = (1..500).random()
var wheels: Int
fun move(movable: Movable): String
}

class Car(_name: String, override var wheels: Int = 4) : Movable {
override var maxSpeed: Int
get() = super.maxSpeed
set(value) {}

override fun move(movable: Movable): String {
return "";
}

}

fun main() {
(1..100).forEach {
println((1..3).random())
}
}

Kotlin 接口 interface 默认实现了open。并且可以提供默认实现_android_02

 和Java不同。kotlin的接口可以实现默认参数。