O'Reilly logo

Object–Oriented Programming with Swift 2 by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required