Scala – Constructors/Modifiers

  • date 8th October, 2020 |
  • by Prwatech |


1. Primary Constructor – compiler creates a constructor which is known as primary constructor. All the statements of class body treated as part of constructor. It is also known as default constructor.

      Run the following program to execute Primary Constructor:


2. Scala Secondary (auxiliary) Constructor – Let’s call primary constructor from inside the auxiliary constructor. This keyword is used to call constructor from other constructor. When calling other constructor make it first line in your constructor.

Run the following command to execute secondary (auxiliary) constructor:





1.     No Modifiers

2.     Private

3.     Protected

Accessibility chart:

  Outside Package Same Package Same Class Sub Class Companion Class
No Modifier Yes Yes Yes Yes Yes
Private No No Yes No Yes
Protected No No Yes Yes Yes


·  Singleton Object

·  Companion Class

Example program of Singleton Object

Quick Support

image image