Skip to content

Instantly share code, notes, and snippets.

@abhimuralidharan
Last active February 20, 2017 06:39
Show Gist options
  • Select an option

  • Save abhimuralidharan/91084ffb2bd03f39def6005fa204de59 to your computer and use it in GitHub Desktop.

Select an option

Save abhimuralidharan/91084ffb2bd03f39def6005fa204de59 to your computer and use it in GitHub Desktop.
//: 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