Last active
February 20, 2017 06:39
-
-
Save abhimuralidharan/91084ffb2bd03f39def6005fa204de59 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //: Playground - noun: a place where people can play | |
| import UIKit | |
| class Vehicle { | |
| var model: String! | |
| var tires = 4 | |
| var currentSpeed: Double = 0 | |
| init() { | |
| } | |
| func drive() { | |
| } | |
| func accelerate(_ speedIncrease: Double) { // super class method. | |
| currentSpeed += speedIncrease * 2 | |
| } | |
| func stop() { | |
| } | |
| } | |
| class SportsCar: Vehicle { | |
| override init() { | |
| super.init() | |
| model = "Ferrari" | |
| } | |
| override func accelerate(_ speedIncrease: Double) { | |
| currentSpeed += speedIncrease * 5 // override the superclass method and increase the acceleration to 5 times the normal acceleration | |
| } | |
| } | |
| class Truck: Vehicle { | |
| override init() { | |
| super.init() | |
| model = "Tata Prima" | |
| } | |
| override func accelerate(_ speedIncrease: Double) { | |
| currentSpeed += speedIncrease // override the superclass method and reduce the acceleration | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment