0
0
Swiftprogramming~10 mins

Protocol inheritance in Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a protocol named Vehicle.

Swift
protocol [1] {
    func startEngine()
}
Drag options to blanks, or click blank then click option'
AVehicle
BStartable
CEngine
DCar
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name instead of a protocol name.
Using a lowercase name for the protocol.
2fill in blank
medium

Complete the code to make Car protocol inherit from Vehicle.

Swift
protocol Car: [1] {
    func openTrunk()
}
Drag options to blanks, or click blank then click option'
AStartable
BVehicle
CDriveable
DEngine
Attempts:
3 left
💡 Hint
Common Mistakes
Using a protocol that is unrelated to Vehicle.
Forgetting to use a colon for inheritance.
3fill in blank
hard

Fix the error in the protocol inheritance declaration.

Swift
protocol ElectricCar [1] Car {
    func chargeBattery()
}
Drag options to blanks, or click blank then click option'
A:
Binherits
Cextends
Dimplements
Attempts:
3 left
💡 Hint
Common Mistakes
Using words like 'inherits' or 'extends' instead of a colon.
Missing the colon entirely.
4fill in blank
hard

Fill both blanks to create a protocol HybridCar that inherits from Car and ElectricCar.

Swift
protocol HybridCar [1] Car [2] ElectricCar {
    func switchPowerMode()
}
Drag options to blanks, or click blank then click option'
A:
B,
Cinherits
Dextends
Attempts:
3 left
💡 Hint
Common Mistakes
Using words like 'inherits' or 'extends' instead of symbols.
Forgetting the comma between protocols.
5fill in blank
hard

Complete the code to define a protocol FlyingCar that inherits from Car, ElectricCar, and Flyable.

Swift
protocol FlyingCar : Car, [1] , Flyable {
    func fly()
}
Drag options to blanks, or click blank then click option'
A:
B,
CFlyable
DElectricCar
Attempts:
3 left
💡 Hint
Common Mistakes
Using words instead of symbols for inheritance.
Incorrect order or missing commas between protocols.