Constructors and Modifiers in Scala Programming Language

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

Constructor:

1.     Default

2.     Primary

Q. What is the difference between Primary constructor and function?

          Constructor is defined within the class

Modifiers:

1.     No Modifiers

2.     Private

3.     Protected

Accessibility chart:

 Outside PackageSame PackageSame ClassSub ClassCompanion Class
No ModifierYesYesYesYesYes
PrivateNoNoYesNoYes
ProtectedNoNoYesYesYes

 

·  Singleton Object

·  Companion Class

Example program of Singleton Object

Quick Support

image image