Advertisement
Guest User

Inheritance

a guest
Apr 7th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.60 KB | None | 0 0
  1. import Foundation
  2.  
  3. class Car{
  4.     var topSpeed = 200
  5.  
  6.     func drive(){
  7.         print("Driving at \(topSpeed)")
  8.     }
  9. }
  10.  
  11. let myRide = Car()
  12.  
  13. class FutureCar : Car{      //inherited car class
  14.  
  15.     override func drive(){          //override is used for modyfying anything from the superclass Car
  16.         super.drive()               //super is used to access and get the superclass
  17.         print("Driving at (after boosting) \(topSpeed + 50)")
  18.     }
  19.  
  20.     func fly(){
  21.         print("Flying")
  22.     }
  23. }
  24. let myFutureRide = FutureCar()
  25. print(myFutureRide.topSpeed)
  26. print(myFutureRide.drive())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement