Declaring classes that inherit from another class

The following lines show the code for the Animal base class in Swift. The class header doesn't specify a base class, so this class will become our base class for the other classes. The code file for the sample is included in the swift_3_oop_chapter_04_01 folder:

 open class Animal { open static var numberOfLegs: Int { get { return 0; } } open static var averageNumberOfChildren: Int { get { return 0; } } open static var abilityToFly: Bool { get { return false; } } open var age: Int init(age : Int) { self.age = age print("Animal created") } open static func printALeg() { preconditionFailure("The pringALeg method must be overriden") } open func printLegs() { for _ in 0..<type(of: self).numberOfLegs ...

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.