Bird
0
0

How can you use protocol inheritance to create a protocol FlyingVehicle that requires all Vehicle protocol requirements plus a method fly()?

hard📝 Application Q9 of 15
iOS Swift - Swift Language Essentials
How can you use protocol inheritance to create a protocol FlyingVehicle that requires all Vehicle protocol requirements plus a method fly()?
Aprotocol FlyingVehicle implements Vehicle { func fly() }
Bprotocol FlyingVehicle { inherit Vehicle; func fly() }
Cprotocol FlyingVehicle extends Vehicle { func fly() }
Dprotocol FlyingVehicle: Vehicle { func fly() }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Swift syntax for protocol inheritance

    Swift uses colon (:) to indicate a protocol inherits from another protocol.
  2. Step 2: Check method addition

    The new protocol adds the method fly() as required.
  3. Step 3: Evaluate options

    protocol FlyingVehicle: Vehicle { func fly() } correctly uses colon and adds fly(). Other options use invalid keywords.
  4. Final Answer:

    protocol FlyingVehicle: Vehicle { func fly() } -> Option D
  5. Quick Check:

    Protocol inheritance uses ':' syntax [OK]
Quick Trick: Use ':' to inherit protocols in Swift [OK]
Common Mistakes:
  • Using 'inherit', 'extends', or 'implements'
  • Forgetting colon
  • Incorrect method syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes