Skip to content
Justice Tech School

Inheritance

A class inherits with a colon. override replaces a method and super calls the parent.

Example
class Animal { func sound() -> String { "..." } }
class Cat: Animal { override func sound() -> String { super.sound() + " meow" } }
print(Cat().sound())

Exercise

Replace a method.

 func sound()

Quiz Test

What does super do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.