Bird
0
0

Which statement correctly describes the difference between struct and class in Swift?

easy📝 Conceptual Q11 of 15
iOS Swift - Swift Language Essentials
Which statement correctly describes the difference between struct and class in Swift?
A<code>class</code> is copied on assignment but <code>struct</code> is shared.
B<code>struct</code> is a value type and <code>class</code> is a reference type.
C<code>struct</code> supports inheritance but <code>class</code> does not.
D<code>struct</code> can only have stored properties, <code>class</code> cannot.
Step-by-Step Solution
Solution:
  1. Step 1: Understand value vs reference types

    In Swift, struct is a value type, meaning it is copied when assigned or passed around. class is a reference type, meaning instances share the same reference.
  2. Step 2: Evaluate each option

    struct is a value type and class is a reference type. correctly states the difference. struct supports inheritance but class does not. is wrong because struct does not support inheritance. class is copied on assignment but struct is shared. reverses the behavior. struct can only have stored properties, class cannot. is false because class can have stored properties.
  3. Final Answer:

    struct is a value type and class is a reference type. -> Option B
  4. Quick Check:

    Value type = struct, Reference type = class [OK]
Quick Trick: Remember: structs copy, classes share references [OK]
Common Mistakes:
  • Confusing value and reference types
  • Thinking structs support inheritance
  • Assuming classes are copied on assignment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes