Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Vehicle {
- var currentSpeed = 1.0
- var description: String {
- return "The current speed is (currentSpeed) miles per hour"
- }
- func makeNoise() {
- }
- }
- class Car: Vehicle {
- var gear = 0
- override var description: String {
- return super.description + " in gear (gear)"
- }
- }
- class AutomaticCar: Car {
- override var currentSpeed: Double {
- get {
- return super.currentSpeed
- }
- set {
- gear = Int(newValue/10) + 1
- }
- }
- }
- let automaticCar = AutomaticCar()
- automaticCar.currentSpeed = 12.0
- print(automaticCar.currentSpeed)//It prints "1.0"
- 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