0 votes
in Scala Constructs by
Explain the different access modifiers that are available in Scala.

1 Answer

0 votes
by

Using access modifiers, you can limit the scope to particular regions of code. Scala has three access modifiers: public, private, and protected. If you wish to use an access modifier, you must include its keywords private/protected/public in the definition of a member of the package, class, or object. By default, the access modifier is public if neither of these keywords is used. 

  1. Private: A private member can only be accessed within a class that defines it or through one of its objects.
  2. Protected: Protected members are accessible from sub-classes of the class in which they are defined. This also applies to methods and variables.
  3. Public member: By default, the access modifier is public. In the absence of the private or protected keyword, the compiler will treat the members as public, and it is not necessary to specify "public".
...