Class Inheritance and the super Keyword
Subclassing, calling super.init() and extending superclass behaviour.
Welcome
Classes support inheritance — a subclass can extend or specialise a superclass. This enables code reuse and polymorphism, core pillars of object-oriented design.
Defining a Subclass
```swift
class Animal {
var name: String
init(name: String) { self.name = name }
func speak() { print("...") }
}
class Dog: Animal {
func fetch() { print("\(name) fetches!") }
}
let d = Dog(name: "Rex")
d.speak() // "..."
d.fetch() // "Rex fetches!"
```
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