Scala Class new

Scala is a language that join both worlds “Functional Programming” and “Object Oriented”.

We talked a little bit about “Functional Programming” in the previous SKBs and today we are going to introduce the basics for “Object Oriented” : the classes and more specifically how to create an instance of a class.

We will be diving a bit more into the theory after the exercise.

A class is a collection of functions that can be reused. This collection is created with parameters and that will make the instance of the class behave differently.

In a lot of programming books, you will see a class being described as a “blueprint”. And using this “blueprint”, you are able to “instantiate”, or build, an object.

The way to build a class in Scala is using the keyword new.

To summarize all the terminology:

  • Class: A collection of methods, values. Built with parameter(s). Instantiated to an object via the keyword new.
  • Object: An instance of a class built with specific parameters.
  • Instantiate: The action of creating an object from a class.
  • new: The keyword used in Scala to instantiate a class and make an object.
  • Field: The val contained in the class.
  • Method: The def (functions) contained in the class.
  • Member: A term to describe both field and method.

Reveal more information and clues
Load Exercise