The basics of Scala access modifiers

Image for post
Image for post
Photo by Gleren Meneghin on Unsplash
package com.exampleclass ToyExample(initialCounter: Int) {
private[this] var counter = initialCounter // Instance private
private[com.example] val someField = ~initialCounter
// Package private
private def getCounter: Int = counter // Class private}
package com.exampleclass SomeClass(private val label: String) {  protected def getLabel: String = this.label.toUpperCase}
package com.exampleclass ToyExample(initialCounter: Int) {
// ...the fields, and getCounter() go here...
def attemptAccess(someObject: SomeClass): Unit = {
println(someObject.getLabel) // ERROR!!!
}
}

is a composer and photographer from Detroit, Michigan. He has been working on a Java program to display certain mathematical diagrams.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store