override, final and Preventing Subclassing
Overriding methods/properties and sealing classes with final.
Welcome
The `override` keyword lets subclasses replace superclass implementations. `final` prevents further overriding or subclassing, protecting your API contract.
override Methods
```swift
class Animal {
func speak() { print("...") }
}
class Cat: Animal {
override func speak() { print("Meow") }
}
Cat().speak() // "Meow"
```
`override` is mandatory — the compiler rejects accidental shadowing.
All lessons in this course
- Class Inheritance and the super Keyword
- override, final and Preventing Subclassing
- Type Casting: is, as?, as! and as
- Deinitializers and Memory Lifecycle