Recall & Review
beginner
What does it mean that inheritance is class-only in Swift?
In Swift, only classes can inherit from other classes. Structures and enums cannot use inheritance. This means you can create a new class based on an existing class, but you cannot do this with structs or enums.Click to reveal answer
intermediate
Why can't structs and enums use inheritance in Swift?
Structs and enums are value types in Swift, which means they are copied when assigned or passed around. Inheritance requires reference semantics, where one object can share behavior and state with another. Because structs and enums are copied, inheritance doesn't fit their design.
Click to reveal answer
intermediate
How does Swift's use of protocols relate to inheritance?
Swift uses protocols to share behavior across structs, enums, and classes. Protocols allow different types to conform to the same set of rules without inheritance. This provides flexibility without needing inheritance for value types.
Click to reveal answer
beginner
What is a key difference between classes and structs in Swift regarding memory?
Classes are reference types, meaning multiple variables can point to the same instance in memory. Structs are value types, so each variable has its own copy. This difference is why inheritance works only with classes.
Click to reveal answer
beginner
Can you explain inheritance in Swift using a real-life example?
Think of a class as a blueprint for a car. You can create a new blueprint for a sports car that inherits features from the basic car blueprint but adds new features. Structs are like photocopies of a drawing; each copy is independent and can't inherit changes from others.Click to reveal answer
Which Swift type supports inheritance?
✗ Incorrect
Only classes in Swift support inheritance. Structs and enums do not.
Why is inheritance limited to classes in Swift?
✗ Incorrect
Inheritance requires reference semantics, which classes have. Structs and enums are value types and do not support inheritance.
What Swift feature allows sharing behavior without inheritance?
✗ Incorrect
Protocols define rules that types can follow, allowing shared behavior without inheritance.
What happens when you assign a struct to a new variable in Swift?
✗ Incorrect
Structs are value types, so assigning them creates a copy.
Which statement is true about classes in Swift?
✗ Incorrect
Classes are reference types and can inherit from other classes.
Explain why inheritance is limited to classes in Swift and not available for structs or enums.
Think about how data is copied or shared in Swift types.
You got /4 concepts.
Describe how Swift uses protocols to share behavior without inheritance.
Protocols are like contracts that types agree to follow.
You got /4 concepts.