Recall & Review
beginner
What is a base class in Swift?A base class is a class that other classes can inherit from. It provides common properties and methods that subclasses can use or override.Click to reveal answer
beginner
What is a subclass in Swift?A subclass is a class that inherits from a base class. It can use or change the properties and methods of the base class and add new ones.Click to reveal answer
beginner
How do you declare a subclass in Swift?You declare a subclass by writing the subclass name followed by a colon and the base class name. For example: <code>class Dog: Animal { }</code>Click to reveal answer
intermediate
What does the
override keyword do in Swift subclasses?The <code>override</code> keyword tells Swift that you want to replace a method or property from the base class with your own version in the subclass.Click to reveal answer
beginner
Can a subclass access properties of its base class?Yes, a subclass can access and use the properties and methods of its base class unless they are marked as private.Click to reveal answer
How do you declare a subclass named
Car that inherits from a base class Vehicle in Swift?✗ Incorrect
In Swift, you declare a subclass by writing the subclass name followed by a colon and the base class name.
What keyword must you use to replace a base class method in a subclass?
✗ Incorrect
The
override keyword is used to replace a method or property from the base class in the subclass.If a property in the base class is marked
private, can the subclass access it?✗ Incorrect
Private properties are not accessible by subclasses.
Which of these is true about subclasses?
✗ Incorrect
Subclasses can add new properties and override existing methods from the base class.
What is the main benefit of using a base class and subclass?
✗ Incorrect
Base classes and subclasses help organize code and reuse common properties and methods.
Explain what a base class and a subclass are in Swift and how they relate to each other.
Think about a parent and child relationship in real life.
You got /4 concepts.
Describe how you would override a method in a Swift subclass and why you might want to do that.
Imagine changing a recipe to make it your own.
You got /4 concepts.