The visibility access rules we have discussed for fields apply to properties as well. This means that you can have private, protected, or public (the default) properties. Furthermore, the setter can have different, more restrictive visibility than the getter, as shown in the following code (the getter code is generated for you automatically in the following case):
class WithPrivateSetter(property: Int) { var SomeProperty: Int = 0 private set(value) { field = value } init { SomeProperty = property } } val withPrivateSetter = WithPrivateSetter(10) println("withPrivateSetter:${withPrivateSetter.SomeProperty}")
There are scenarios where properties are subject to class inheritance. If this happens, typically protected visibility, at least for the setter, is more appropriate, as shown...