Skip to content

Instantly share code, notes, and snippets.

@Jesus
Created November 23, 2019 09:52
Show Gist options
  • Save Jesus/3dc5a18c60185b53e1ab4bb6187e2cf2 to your computer and use it in GitHub Desktop.
Save Jesus/3dc5a18c60185b53e1ab4bb6187e2cf2 to your computer and use it in GitHub Desktop.
open class Vehicle {
// open fun startEngine() = println("Vroom!")
}
open class Car : Vehicle() {
// open override fun startEngine() = println("Vroom vroom!")
}
fun Vehicle.startEngine() {
println("Vroom!")
}
fun Car.startEngine() {
println("Vroom vroom!")
}
fun main() {
val v = Vehicle()
val c = Car()
v.startEngine() // => "Vroom!"
c.startEngine() // => "Vroom vroom!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment