Sobes.tech
Junior — Senior

What is the print result of Swift code №26

livecode

Task condition

This example demonstrates how a protocol method with a default implementation works and how it can be overridden in a specific class. Note that the variable is declared as a protocol type, and methods are called both as on the protocol and on the implementation class.

protocol Animal {
    func say()
}

extension Animal {
    func say() {
        print("Animal")
    }
}

class Cat: Animal {
    func say() {
        print("Cat")
    }
}

let cat: Animal = Cat()
cat.say()
Cat().say()