Scala trait

trait are like interface from other languages.

Have fun with it !

trait allows you to describe what a class should look like.

You can implement functions that can be overridden. You can describe functions that have to be overridden.

New terms:

  • to inherit: the action of extending a class
  • Child: the class that inherit from a trait
  • Parent: the class that is inherited from

Several new keywords today:

  • extends: is the keyword to be able to inherit from a class
  • override: tell that this element has been overridden.
  • final: tell that this cannot be overridden
  • protected: similar to private but allow the child class to see this element. private would not allow the child to see it.

Reveal more information and clues
Load Exercise