Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Driver(val vehicle: Vehicle){
- fun honk() {vehicle.honk()}
- }
- abstract class Vehicle {
- abstract fun honk()
- }
- class Taxi : Vehicle() {
- override fun honk() {
- println("ba!ba!")
- }
- }
- class Truck : Vehicle() {
- override fun honk() {
- println("boooom...")
- }
- }
- fun main(args: Array<String>) {
- val taxi = Taxi()
- val taxiDriver = Driver(taxi)
- taxiDriver.honk()
- // ba!ba!
- val truck = Truck()
- val truckDriver = Driver(truck)
- truckDriver.honk()
- // boooom...
- }
Add Comment
Please, Sign In to add comment