Skip to content

Instantly share code, notes, and snippets.

@biloshkurskyi-ss
Last active July 30, 2019 11:11
Show Gist options
  • Save biloshkurskyi-ss/e4ce63c3f8fae32a77587d8434f625ef to your computer and use it in GitHub Desktop.
Save biloshkurskyi-ss/e4ce63c3f8fae32a77587d8434f625ef to your computer and use it in GitHub Desktop.
OOP at Swift - Inheritance
import Foundation
class Vehicle {
var model: String
var make: Int
init(model: String, make: Int) {
self.model = model
self.make = make
}
func start() { print("Vehicle - Start") }
func stop() { print("Vehicle - Stop") }
}
let сuriosity = Vehicle(model: "Rover", make: 2011)
class Car: Vehicle {
var tireCount: Int
init(model: String, make: Int, tireCount: Int = 4) {
self.tireCount = tireCount
super.init(model: model, make: make)
}
override func start() {
print("Car - Start")
}
override func stop() {
super.stop()
}
}
let ford = Car(model: "Ford", make: 2018)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment