Suppose I have two classes:
private[example] class PoorInt extends Int
class RichInt private[example] extends Int
The question is what's the difference between private modifier position in these classes declarations?
Suppose I have two classes:
private[example] class PoorInt extends Int
class RichInt private[example] extends Int
The question is what's the difference between private modifier position in these classes declarations?
The first refers to the scope of the class, i.e. you cannot access PoorInt
outside package example
.
The second refers to the scope of the constructor of RichInt
, which you are not providing explicitly, i.e. you cannot use its constructor outside package example
.
For example:
// somewhere outside package example ...
val x = new RichInt // doesn't compile. Constructor is private
val y : PoorInt = ... // doesn't compile. PoorInt is not accessible from here
def f(x: PoorInt) = ... // doesn't compile. PoorInt is not accessible from here
You can also see this question.