If I understand correctly, you want the name and surname fields in Son be immutable, unlike those in Person, which are vars.
It is simply not possible. The only way to do this is to overwrite:
class Person (var name: String, var surname: String) //this won't compile class Son(override val name: String, override val surname: String) extends Person(name, surname)
In Scala, you cannot rewrite var with val - and it's pretty obvious why - subclasses can override or add functionality to a superclass . If we hoped that vals redefined vars, we would remove the installer from the parent class for the overridden field. This violates the is-a relationship implied by inheritance.
What you can do is implement:
trait Person { def name: String def surname: String } //this is fine now class Son(val name: String, val surname: String) extends Person //in case you want a type of person which can be changed. class MutablePerson(var name: String, var surname: String) extends Person
Person now a sign - it just provides a way to get name or surname . Son overrides Person with vals - and therefore, you are guaranteed that no one else will change the fields in Son .
In your example, I assume that you still want to have a Person type that you can change. And you can do this using the MutablePerson class above, which allows you to change its fields.
Hope this helps!
source share