Scala by Example

Scala is a multi-paradigm, static, and strongly typed language on the JVM.

Source

Classes

Classes are a blueprint for creating objects.

Defining a Class

class Book(name: String, author: String) {
  def title = name + " by " + author
}

Creating an Object

Object Instantiation is done using the new keyword

val myBook = new Book("Sherlock Holmes", "Arthur Conan Doyle")

myBook.title

Result:

res0: String = Sherlock Holmes by Arthur Conan Doyle