在java中同一个包中,其它类可以访问本类中的protected成员,其它包中本类的子类可以访问本类的protected成员,但其它类则不能访问本类的protected成员。那么scala中是不是也是这样的权限呢? 我们做个实验:
package p{
class Super{
protected def f(){println(s"protected \n test")}
}
class Sub extends Super{
f()
}
class Other{
(new Super()).f()
}
}