To override a method, property, or subscript, we need to prefix the definition with the
override keyword. This tells the compiler that we intend to override something in the superclass and that we did not make a duplicate definition by mistake. The
override keyword does prompt the Swift compiler to verify that the superclass (or one of its parents) has a matching declaration that can be overridden. If it cannot find a matching declaration in one of the superclasses, an error will be thrown.
Let's look at how we would override a method. We will start by adding a
getDetails() method to the
Plant class that we will then override in the child classes. The following code shows how the new
Plant class ...