Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas

PatilShreyas/1-Vehicle.kt Secret

Last active Dec 30, 2020
Embed
What would you like to do?
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