as expected reassignment is giving error like below in REPL
scala> val a=1
a: Int = 1
scala> a=2
:12: error: reassignment to val
a=2
From Scala docs REPL overview:
- every line of input is compiled separately.
- dependencies on previous lines are included by automatically generated imports.
Combining these two facts, we can understand that they are not in the same namespace, unlike the example you provided which 2 variables called x
are in the same class.