Junior — Senior
What output will we get in example №32
livecode
Task condition
Let's consider an example where the protocol EngineStarter declares the method startEngine(). The class Vehicle implements this protocol, and the class Car inherits from Vehicle and overrides the method. The protocol extension also provides a default implementation. Then, an instance of Car is created and stored in a variable of type EngineStarter. What text will be printed when calling startEngine()?
protocol EngineStarter {
func startEngine()
}
class Vehicle: EngineStarter {
func startEngine() {
print("Vehicle engine started")
}
}
class Car: Vehicle {
override func startEngine() {
print("Car engine started")
}
}
extension EngineStarter {
func startEngine() {
print("Default engine started")
}
}
let car = Car()
let vehicle: EngineStarter = car
vehicle.startEngine()