Table of Contents

Scala - Object (Singleton)

About

Object in Scala are like classes, but for every object definition there is only one single instance (See Design pattern - The Singleton).

It is not possible to create instances of objects using new, instead you can just access the members (methods or fields) of an object using its name.

Example

The below code is in one file with a main hook extending App

package Scala

object HelloWorld extends App {
  println("Hello, World!")
}