Clarity needed in determining the scope of Scala's constructor parameter
As per this link https://alvinalexander.com/scala/how-to-control-visibility-constructor-fields-scala-val-var-private#comment-13237, whenever a constructor parameter is labelled as private, then no getter and setter methods will be created. But the code I have provided here works fine even though the parameter is labelled as private. I went through this StackOverflow link Do scala constructor parameters default to private val?. This one & the above contradicts. Can someone please explain. The code segment is, in fact, available in the StackOverflow link.
class Foo(private val bar: Int) {
def otherBar(f: Foo) {
println(f.bar) // access bar of another foo
}
}
The below line runs fine:
val a = new Foo(1)
a.otherBar(new Foo(3))
It prints 3.
As per the first link, the code should result in compile error because the parameter is private.