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 (:
). The code file for the sample is included in the swift_3_oop_chapter_05_09
folder:
open class AngryCatAlien : AngryCat, Alien {
open 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
}
open func appear() {
print("I'm \(fullName) and you can see my \(numberOfEyes...