Google News
logo
Scala - Interview Questions
Write different types of scope provided for variables in Scala.
According to their declarations, Scala variables are categorized into three scopes as given below:

Fields : Variables of this type can be accessed from any method within a Web object, or from outside the object, depending on access modifiers used. Depending on the var and val keywords, they can be mutable or immutable.

Method Parameters : When a method is invoked, these variables are used to pass values to the method. All method parameters use the val keyword and are strictly immutable. Normally, these are accessed within a method, but a Reference allows accessing them outside the method.

Local Variables : These are the variables (mutable or immutable) declared inside a method and accessible only within that method. By returning them from the method, they can be accessed outside of the method.
Advertisement