Classes in Swift use reference semantics, meaning multiple variables can point to the same instance. This shared mutable state makes inheritance useful to extend or modify behavior. Structs and enums use value semantics, so each copy is independent, making inheritance less meaningful and potentially confusing.
class Animal { func sound() -> String { return "Some sound" } } class Dog: Animal { override func sound() -> String { return "Bark" } } let pet: Animal = Dog() print(pet.sound())
The variable pet is of type Animal but holds an instance of Dog. Because sound() is overridden in Dog, the Dog version is called, printing "Bark".
struct Vehicle { var wheels: Int } struct Car: Vehicle { var brand: String }
Structs in Swift do not support inheritance. Trying to inherit from a struct causes a compile-time error stating inheritance from non-class type is not allowed.
describe() method in a subclass.Option C correctly uses the override keyword and matches the method signature of the parent. Option C misses override. Option C misses the return type and func keyword. Option C changes the return type, which is not allowed.
Swift uses protocols with default implementations in extensions to share behavior across classes, structs, and enums. This approach works around the class-only inheritance limitation and supports value types.