Controlling whether subclasses can or cannot override members

The following lines show the code for the complete Dog class that inherits from DomesticMammal. Note that the following code replaces the previous Dog class that just declared an overridden type property. The code file for the sample is included in the swift_3_oop_chapter_04_07 folder:

    open class Dog: DomesticMammal { open static override var numberOfLegs: Int { get { return 4; } } open static override var abilityToFly: Bool { get { return false; } } open var breed: String { get { return "Just a dog" } } open var breedFamily: String { get { return "Dog" } } private func initializeDog() { print("Dog created") } override init(age: Int, name: String, favoriteToy: String) { super.init(age: ...

Get Swift 3 ObjectOriented Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.