0Pricing
Swift Academy · Lesson

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

  1. Class Inheritance and the super Keyword
  2. override, final and Preventing Subclassing
  3. Type Casting: is, as?, as! and as
  4. Deinitializers and Memory Lifecycle
← Back to Swift Academy