With the following code:
protocol Flier {
func fly()
}
extension Flier {
func fly() { print ("flap")}
}
class Bird: Flier {
func fly() { print("flap-flap") }
}
class SmallBird: Bird {
}
let bird: Flier = SmallBird()
bird.fly()
The console prints "flap-flap" which is what is expected.
Why does console prints "flap" if I declare the same function in a subclass instead of declaring it in a superclass?
protocol Flier {
func fly()
}
extension Flier {
func fly() { print ("flap")}
}
class Bird: Flier {}
class SmallBird: Bird {
func fly() { print ("flap-flap")}
}
let bird: Flier = SmallBird()
bird.fly() //flap