When declaring a class in Scala, you can define the parameters as val
, like this:
class MathOperations(val _x: Int, val _y: Int) {
var x: Int = _x
var y: Int = _y
def product = x*y
}
But in this case, when I leave out the val
keyword, an instance of the class behaves exactly the same (as far as I can figure out)
What is the difference between declaring the parameters as I did above, and doing it without val
, like this:
class MathOperations(_x: Int, _y: Int) {