default access modifier
While in Scala the public keyword doesn’t exist, Java allows you to explicitly use the keyword protected as you please.
Scala makes a special link between a class and its companion object, but not with inner classes as they are not accessible with a private modifier.
Scala is quite restrictive here 😐 (but don’t worry too much, keep reading…)
Finally something that works in the same way! 😀
So far, we could think that the access modifier system in Scala is more limited than the Java one. Actually, it is a lot more powerful than the Java one, thanks to the super powers of qualified access modifiers!
private[X] and protected[X]
We can use this technique to obtain exactly the same meaning of the Java access modifiers:
We can also declare a member as object-private:
This makes sure that the member will not be visible to other objects of the same class…it’s like a super private modifier! 😀