First, we will try to override the numberOfLegs
type property that the Dog
class will inherit from the Animal
base class. We will face an issue and solve it. The following lines show the code for a simplified version of the Dog
class that inherits from DomesticMammal
and just tries to override the numberOfLegs
type property:
public class Dog: DomesticMammal { public static override var numberOfLegs: Int { get { return 4; } } }
After we enter the previous lines in the Playground, we will see the following error message in the line that tries to override the numberOfLegs
type property: error: class var overrides a 'final' class var
. The following screenshot shows the error in the Playground: