Scala - Object (Singleton)

Card Puncher Data Processing


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.


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

package Scala

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

Discover More
Card Puncher Data Processing
Scala - Class

Classes in Scala are: very similar to classes in Java. are templates containing fields and methods. Like in Java, classes can be instantiated using the new construct, there can be many “instances”...
Card Puncher Data Processing
Scala - Main (Top-Level Objects)

In Scala, the main or entry point method is defined in an object. An object can be made executable by either: adding extending the type App or by adding a method object extends the type...
Card Puncher Data Processing
Scala - Source File

Scala source code is stored in text files with the extension .scala. Typically Scala programmers create: one source file for each class, or one source file for a class hierarchy. In fact, Scala...
Card Puncher Data Processing
Scala - Type

Every variable and expression in a Scala program has a type that is known at compile time. A type restricts the possible values to which a variable can refer, or an expression can produce, at run time....

Share this page:
Follow us:
Task Runner