Default and parameterized constructors

The primary constructor for any class defined in Scala is the body itself. It means that whatever you declare and define inside a class body gets instantiated when you make an instance of it. There are other ways to define secondary/auxiliary constructors as well. Take a look at the following case classes:

import java.time.LocalDatecase class Employee(name: String, id: String, contact: String, email: String) 

case class StartUp(name: String, founder: Employee, coFounders: Option[Set[Employee]], members: Option[List[Employee]], foundingDate: Option[LocalDate]) 

We can see two case classes named Employee and StartUp. You may wonder why Employee is specific to our StartUp class. The StartUp case class takes ...

Get Learning Scala Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.