Created
November 23, 2019 09:52
-
-
Save Jesus/3dc5a18c60185b53e1ab4bb6187e2cf2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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