I am having my first experience with Scala, experimenting with basic concepts. I made a very simple class, doing shenanigans with overriding toString for printing the class instance upon creation:
class Person(var firstName: String, var lastName: String) {
println(this)
override def toString: String = "Overriden toString"
println(this)
}
val p = new Person("John", "Smith")
I wondered what would happen if I run this code. First println before overriding toString is supposed to be
PlatformName$Person@address
if I understand it correctly, which is what you supposed to get when printing a class instance without overriding toString. But instead, both prints on construction printed
Overriden toString.
Why it is so? Does override takes the first priority over any other code, ignoring the order, or how does it work?