In Java, we can use ‘protected’ keyword to access that component in the same package (within all sub-classes or any other classes which are available in the same package) or any subclass available in any package.
In Scala, ‘protected’ access modifier has different meaning. We can use it in two different ways:
protected
protected[T]
Here “T” parameter can be a Scaa class/trait, package or object.
If we use Non-Parameterized protected that is “protected”, then that is visible only from it’s subclasses. It not visible from the same package or outside.
If we use Parameterized protected that is “protected[T]”, then that is visible from that component only.
Examples:
If we use something like protected[Account] where “Account” is a Scala class, then that is visible within that class only. It is not visisble outside that class.
If we use something like protected[retailbank] where “retailbank” is a Scala package, then that is visible within that package (and sub-packages) only. It is not visible outside that package.