Here, there seems to be a fundamental misunderstanding. All fields in Scala are private. This is not only the default, but also optional.
For example, let's say you have this:
class Address(var street: String)
The field in which street is stored is closed. Say you do it:
val x = new Address("Downing") println(x.street)
This code does not have direct access to the private field for street . x.street is a getter method.
Say you do it:
x.street = "Boulevard"
This code does not directly change the private field for street . x.street = is actually the x.street_= method, which is the setter method.
You cannot directly access fields in Scala. Everything is done through getters and setters. In Scala, each field is private, each field has getters, and each var has setters.
source share