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

Combining inheritance and protocols

We can combine class inheritance with protocol conformance. The following lines show the code for a new AngryCatAlien class that inherits from the AngryCat class and conforms to the Alien protocol. Note that the class declaration includes the superclass (AngryCat) and the implemented protocol (Alien) separated by a comma after the colon (:):

public class AngryCatAlien : AngryCat, Alien { public var numberOfEyes: Int = 0 init (nickName: String, age: UInt, fullName: String, initialScore: UInt, x: UInt, y: UInt, numberOfEyes: Int) { super.init(nickName: nickName, age: age, fullName: fullName, initialScore: initialScore, x: x, y: y) self.numberOfEyes = numberOfEyes } public func appear() { print("I'm \(fullName) ...

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