Recall & Review
beginner
What does it mean to override a method in Swift?
Overriding a method means providing a new version of a method in a subclass that replaces the version defined in its superclass.Click to reveal answer
beginner
How do you indicate that a method or property is being overridden in Swift?
You use the
override keyword before the method or property declaration in the subclass.Click to reveal answer
intermediate
Can you override a property in Swift? If yes, what kinds of properties can be overridden?
Yes, you can override computed properties and property observers, but not stored properties directly.
Click to reveal answer
beginner
What happens if you try to override a method without using the
override keyword?Swift will give a compile-time error because it requires explicit use of
override to avoid accidental overrides.Click to reveal answer
intermediate
Explain how to call the superclass version of an overridden method in Swift.Inside the overriding method, you call
super.methodName() to run the original method from the superclass.Click to reveal answer
Which keyword is required to override a method in Swift?
✗ Incorrect
The
override keyword tells Swift you are replacing a method or property from the superclass.What will happen if you override a method but forget to write the
override keyword?✗ Incorrect
Swift requires the
override keyword to prevent accidental overrides, so it gives an error if missing.How do you call the original method from the superclass inside an overridden method?
✗ Incorrect
Using
super.methodName() calls the superclass version of the method.Which of these can be overridden in Swift?
✗ Incorrect
You can override computed properties and property observers, but not stored properties directly.
Why is overriding useful in programming?
✗ Incorrect
Overriding lets subclasses change or add to the behavior of methods they inherit.
Describe how to override a method in Swift and how to call the original method from the superclass.
Think about the keywords and syntax needed to replace and extend a method.
You got /3 concepts.
Explain what kinds of properties can be overridden in Swift and why stored properties are treated differently.
Consider how properties store or calculate values.
You got /3 concepts.