Junior — Senior
Determining the called method in the protocol hierarchy
livecode
Task condition
The task considers a situation where multiple protocols inherit from each other, and each has its own implementation of the test() method in an extension. It is necessary to understand which implementation will be executed when calling the method on an instance of a class that conforms to several of these protocols simultaneously.
protocol A2 {
func test()
}
protocol B2: A2 {
func test()
}
protocol C2: B2 {
func test()
}
extension A2 {
func test() {
print("A2")
}
}
extension B2 {
func test() {
print("B2")
}
}
extension C2 {
func test() {
print("C2")
}
}
class TestClass2: A2, C2, B2 {}
TestClass2().test()