Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a protocol named Vehicle.
Swift
protocol [1] {
func startEngine()
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name instead of a protocol name.
Using a lowercase name for the protocol.
✗ Incorrect
The protocol is named
Vehicle to represent a general vehicle type.2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a protocol that is unrelated to
Vehicle.Forgetting to use a colon for inheritance.
✗ Incorrect
The
Car protocol inherits from Vehicle to extend its requirements.3fill in blank
hardFix the error in the protocol inheritance declaration.
Swift
protocol ElectricCar [1] Car {
func chargeBattery()
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using words like 'inherits' or 'extends' instead of a colon.
Missing the colon entirely.
✗ Incorrect
In Swift, protocol inheritance uses a colon
: not words like 'inherits' or 'extends'.4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using words like 'inherits' or 'extends' instead of symbols.
Forgetting the comma between protocols.
✗ Incorrect
Use a colon to start inheritance and commas to separate multiple protocols.
5fill in blank
hardComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using words instead of symbols for inheritance.
Incorrect order or missing commas between protocols.
✗ Incorrect
Start inheritance with a colon, then list protocols separated by commas.