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
|Outside Package||Same Package||Same Class||Sub Class||Companion Class|
· Singleton Object
· Companion Class
Example program of Singleton Object