Scala Language Scope Protected scope


The protected scope allows the value to be accessed from any subclasses of the current class.

class FooClass {
  protected val x = "foo"
class BarClass extends FooClass {
  val y = x // It is a subclass instance, will compile
class ClassB {
  val f = new FooClass
  f.x // <- This will not compile