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:

Two way


object extends the type App trait

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

If that object extends trait App, then all statements contained in that object will be executed. otherwise you have to add a method main which will act as the entry point of your program.


object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, World!")

Powered by ComboStrap