Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Last active December 30, 2020 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatilShreyas/bb2002cb21b8fef20e995b2fd032973e to your computer and use it in GitHub Desktop.
Save PatilShreyas/bb2002cb21b8fef20e995b2fd032973e to your computer and use it in GitHub Desktop.
interface Vehicle {
fun drive()
}
class Bike(val speed: Double): Vehicle {
override fun drive() = println("Driving Bike at $speed KMPH")
}
class Car(val speed: Double): Vehicle {
override fun drive() = println("Driving Car at $speed KMPH")
}
class SportsBike(v: Vehicle): Vehicle by v
class SportsCar(v: Vehicle): Vehicle by v
fun main() {
val bike = Bike(50.0)
SportsBike(bike).drive() // prints "Driving Bike at 50.0 KMPH"
val car = Car(100.0)
SportsCar(car).drive() // prints "Driving Car at 100.0 KMPH"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment