[Kotlin] interface

import java.util.*

/**
 * You can edit, run, and share this code. 
 * play.kotlinlang.org 
 */
interface Driveable {
    fun drive() 
}

interface Buildable {
    val timeRequired: Int
    fun build()
}

class Car(val color: String): Driveable {
    override fun drive() {
        println("Driving Car")
    }
}

class MotorCycle(val color: String): Driveable, Buildable {
    override val timeRequired = 120
    override fun drive() {
        println("Driving motorcycle")
    }
    
    override fun build() {
        println("Build motocycle")
    }
}


fun main() {
    val car: Driveable = Car("blue")
    car.drive()
    val mot = MotorCycle("blue")
    mot.build()
    mot.drive()
}
原文地址:https://www.cnblogs.com/Answer1215/p/13800654.html