-
-
Save PatilShreyas/bb2002cb21b8fef20e995b2fd032973e to your computer and use it in GitHub Desktop.
This file contains 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
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") | |
} |
This file contains 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
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