Last active
July 30, 2019 11:11
-
-
Save biloshkurskyi-ss/e4ce63c3f8fae32a77587d8434f625ef to your computer and use it in GitHub Desktop.
OOP at Swift - Inheritance
This file contains 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
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