0Pricing
Swift Academy · Lesson

Inheritance, overriding & final

Create a base class, extend it via inheritance, override methods/properties, call super , and lock behavior with final .

Inheritance, overriding & final is a free Swift Academy lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Overview

Swift classes support inheritance. You can override behavior and call super. Use final to lock things down.

Base class

Create a base class with an instance method that subclasses can override.

class Animal {
    var name: String
    init(name: String) { self.name = name }
    func speak() -> String { "..." }     // to be overridden
}
let a = Animal(name: "Thing")
print(a.speak())

Override method

Use the override keyword when providing a new implementation in a subclass.

class Dog: Animal {
    override func speak() -> String { "woof" }
}
let d = Dog(name: "Rex")
print(d.speak())  // "woof"

super call

Call super to reuse base behavior and extend it in the subclass.

class Cat: Animal {
    override func speak() -> String {
        let base = super.speak()
        return base + " meow"
    }
}
print(Cat(name: "Mimi").speak())  // "... meow"

Override & final

Override properties and methods. Use final on a class or member to stop further subclassing/overriding.

class Vehicle {
    var description: String { "vehicle" }        // computed property
    func drive() { print("move") }
}
class Car: Vehicle {
    override var description: String { "car" }   // override property
    override func drive() { print("vroom") }
}
final class ElectricCar: Car {                   // cannot be subclassed
    final override func drive() { print("zzzz") } // cannot be overridden further
}
let e = ElectricCar()
print(e.description)
e.drive()

Notes & tips

Notes:

  • Prefer composition over deep hierarchies.
  • Mark classes or members final unless you intend extension by subclassing.
  • Always use override when replacing base behavior.

final keyword

Quick check: Which keyword blocks subclassing/overriding?

Recap

Recap: Define a base class, override methods/properties in subclasses, call super to reuse work, and mark types/members final to lock behavior.

Frequently asked questions

Is the “Inheritance, overriding & final” lesson free?

Yes — the full text of “Inheritance, overriding & final” is free to read here on the web, and the Swift Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.

What will I learn in “Inheritance, overriding & final”?

Create a base class, extend it via inheritance, override methods/properties, call super , and lock behavior with final . You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Swift Academy?

No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Inheritance, overriding & final” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Swift Academy lesson?

Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Memberwise init & mutating methods
  2. Inheritance, overriding & final
  3. Access control (public/internal/fileprivate/private)
← Back to Swift Academy