xxxxxxxxxx
interface MyInterface {
var test: String // abstract property
fun foo() // abstract method
fun hello() = "Hello there" // method with default implementation
}
xxxxxxxxxx
interface MyInterface {
val test: Int // abstract property
fun foo() : String // abstract method (returns String)
fun hello() { // method with default implementation
// body (optional)
}
}
class InterfaceImp : MyInterface {
override val test: Int = 25
override fun foo() = "Lol"
// other code
}
xxxxxxxxxx
fun main() {
Child().hairColour() /// brown
Child().eyeColour() /// blue
}
interface Parent {
val eyeColour: String
get() = "blue"
val hairColour: String
get() = "black"
fun eyeColour() {
println(eyeColour)
}
fun hairColour() {
println(hairColour)
}
}
class Child : Parent {
override val hairColour = "brown"
}