Guest User

Untitled

a guest
Apr 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. class Vehicle {
  2. var currentSpeed = 1.0
  3. var description: String {
  4. return "The current speed is (currentSpeed) miles per hour"
  5. }
  6. func makeNoise() {
  7. }
  8. }
  9. class Car: Vehicle {
  10. var gear = 0
  11. override var description: String {
  12. return super.description + " in gear (gear)"
  13. }
  14. }
  15. class AutomaticCar: Car {
  16. override var currentSpeed: Double {
  17. get {
  18. return super.currentSpeed
  19. }
  20. set {
  21. gear = Int(newValue/10) + 1
  22. }
  23. }
  24. }
  25. let automaticCar = AutomaticCar()
  26. automaticCar.currentSpeed = 12.0
  27. print(automaticCar.currentSpeed)//It prints "1.0"
  28. print(automaticCar.description)//It prints "The current speed is 1.0 miles per hour in gear 2"
Add Comment
Please, Sign In to add comment