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.
- Private: A private member can only be accessed within a class that defines it or through one of its objects.
- Protected: Protected members are accessible from sub-classes of the class in which they are defined. This also applies to methods and variables.
- 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".